Created the projects.ts controller
This commit is contained in:
parent
72cd42dc09
commit
5d8237419f
22
src/controller/projects.ts
Normal file
22
src/controller/projects.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { Project } from "@models/Project";
|
||||||
|
import { encryptClearField } from "@utils/decryption";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
|
export const createProject = async (name: string, userId?: string) => {
|
||||||
|
const count = await Project.countDocuments({ creatorId: encryptClearField(userId || "") });
|
||||||
|
if (count > 5) return { code: 95, message: "You have exceeded the project limit" };
|
||||||
|
|
||||||
|
await Project.create({ name, creatorId: userId });
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteProject = async (id: string) => {
|
||||||
|
if (!Types.ObjectId.isValid(id))
|
||||||
|
return { code: 3, message: "Invalid object id provided" };
|
||||||
|
|
||||||
|
const project = await Project.findById(id);
|
||||||
|
if (project === null) return { code: 5009, message: "The provided project id does not exist" };
|
||||||
|
|
||||||
|
// TODO: Delete all licenses, groups, permissions, ..
|
||||||
|
|
||||||
|
await project.delete();
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user