Updated the projects.ts controller
This commit is contained in:
parent
69fef9b9b5
commit
e5190ae82b
@ -1,9 +1,10 @@
|
|||||||
import { IProject, Project } from "@models/Project";
|
import { IProject, IProjectPlan, Project } from "@models/Project";
|
||||||
import { encryptClearField } from "@utils/decryption";
|
import { encryptClearField } from "@utils/decryption";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { IKeyRole } from "@models/AccessKey";
|
import { IKeyRole } from "@models/AccessKey";
|
||||||
import { Member } from "@models/Member";
|
import { Member } from "@models/Member";
|
||||||
|
import { planLimits } from "../limits/plans";
|
||||||
|
|
||||||
export const checkProjectAccess = (requiredPermission: IKeyRole) => async (userId: string, projectId: string) => {
|
export const checkProjectAccess = (requiredPermission: IKeyRole) => async (userId: string, projectId: string) => {
|
||||||
if (!Types.ObjectId.isValid(projectId))
|
if (!Types.ObjectId.isValid(projectId))
|
||||||
@ -50,8 +51,11 @@ export const getProject = async (projectId: string, userId: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const createProject = async (name: string, userId: string) => {
|
export const createProject = async (name: string, userId: string) => {
|
||||||
const count = await Project.countDocuments({ creatorId: encryptClearField(userId) });
|
const count = await Project.countDocuments({ creatorId: encryptClearField(userId),
|
||||||
if (count > 5) return { code: 95, message: "You have exceeded the project limit" };
|
plan: encryptClearField(IProjectPlan.PERSONAL) });
|
||||||
|
|
||||||
|
if (count > planLimits["account"].FREE_PROJECTS) return { code: 95, message: "You have exceeded the free project limit" };
|
||||||
|
if (count > 100) return { code: 95, message: "You have exceeded the project limit" };
|
||||||
|
|
||||||
await Project.create({ name, creatorId: userId });
|
await Project.create({ name, creatorId: userId });
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user