Added error if permission already exists on creating a page permission

This commit is contained in:
devanshu052000 2025-04-22 16:16:23 +05:30
parent 0eb16f55e7
commit b1f3c12995
2 changed files with 18 additions and 2 deletions

@ -1 +1 @@
Subproject commit f18319f145367e9f6a66110f16587d858470f166
Subproject commit 472e07a6f66a7c80e42b18256511e8c3a6829eb4

View file

@ -13,10 +13,21 @@ export class PagePermissionsRepository extends Repository<PagePermission> {
async getPagePermissions(pageId: string, manager?: EntityManager): Promise<PagePermission[]> {
return dbTransactionWrap(async (manager: EntityManager) => {
return manager.find(PagePermission, {
const pagePermissions = await manager.find(PagePermission, {
where: { pageId },
relations: ['users', 'users.user', 'users.permissionGroup'],
});
return pagePermissions.map((permission) => {
if (permission.type === PAGE_PERMISSION_TYPE.GROUP) {
return {
...permission,
groups: permission.users,
users: undefined,
};
}
return permission;
});
}, manager || this.manager);
}
@ -26,6 +37,11 @@ export class PagePermissionsRepository extends Repository<PagePermission> {
manager?: EntityManager
): Promise<PagePermission> {
return dbTransactionWrap(async (manager: EntityManager) => {
const existingPermission = await manager.findOne(PagePermission, { where: { pageId } });
if (existingPermission) {
throw new Error(`Page permission already exists for Page id: ${pageId}`);
}
const pagePermission = manager.create(PagePermission, {
pageId,
type,