[INIT] Initial Project Structure
This commit is contained in:
commit
0fc5f05b6a
105 changed files with 10448 additions and 0 deletions
34
lib/database/tables/ProjectTableService.ts
Normal file
34
lib/database/tables/ProjectTableService.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import config from "@lib/config";
|
||||
import TableService from "../TableService";
|
||||
import { CProjectContract } from "@lib/types/ContractTypes";
|
||||
import { ProjectErrors } from "@lib/vix/ClientErrors";
|
||||
import { VERB } from "@dunemask/vix/logging";
|
||||
|
||||
export default class ProjectTableService extends TableService {
|
||||
protected table = "Project";
|
||||
async byId(projectId: string) {
|
||||
return this.pg.project.findUnique({ where: { id: projectId } });
|
||||
}
|
||||
|
||||
async bySlug(slug: string) {
|
||||
return this.pg.project.findUnique({ where: { slug } });
|
||||
}
|
||||
|
||||
async $upsertDefaultProject() {
|
||||
const { projectSlug: slug, projectName: name } = config.Server;
|
||||
const createOptions = { slug, name, parentProject: slug };
|
||||
const existingProject = await this.pg.project.findUnique({ where: { slug } });
|
||||
if (!!existingProject) return VERB("PROJECT", "Default project already exists!");
|
||||
VERB("PROJECT", "Default project not found! Creating now!");
|
||||
const proj = await this.pg.project.upsert({ where: { slug }, create: createOptions, update: createOptions });
|
||||
await this.pg.project.update({ where: { id: proj.id }, data: { parentProject: proj.id } }); // Use ProjectID instead of slug
|
||||
}
|
||||
|
||||
async create(project: CProjectContract["Create"] & { parentProject: string }) {
|
||||
const existingProject = await this.pg.project.findMany({ where: { id: project.slug } });
|
||||
if (existingProject.length > 1) throw ProjectErrors.BadRequestSlugInvalid;
|
||||
return this.pg.project.create({ data: project }).catch(() => {
|
||||
throw ProjectErrors.ConflictNonUnique;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue