Added a limit check in the permission.ts controller

This commit is contained in:
Mathias Wagner 2023-08-03 23:28:21 +02:00
parent fedee08854
commit dbfc0353f0
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -35,6 +35,9 @@ export const createPermission = async (userId: string, projectId: string, config
const permission = await Permission.findOne({ projectId: encryptClearField(String(access._id)), permission: encryptClearField(configuration.permission) });
if (permission !== null) return { code: 4008, message: "The provided permission name is already in use" };
const count = await Permission.countDocuments({ projectId: encryptClearField(String(access._id)) });
if (count >= planLimits[access.plan].PERMISSIONS) return { code: 95, message: "You have exceeded the permission limit" };
await Permission.create({ ...configuration, projectId });
return {};