Added a limit check in the permission.ts controller

This commit is contained in:
2023-08-03 23:28:21 +02:00
parent fedee08854
commit dbfc0353f0

@ -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) }); 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" }; 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 }); await Permission.create({ ...configuration, projectId });
return {}; return {};