update roles and permissions

This commit is contained in:
2025-12-23 12:07:33 +03:30
parent 4e1300c6b9
commit 9916426814
7 changed files with 28 additions and 55 deletions
@@ -10,9 +10,7 @@ export class Permission extends BaseEntity {
@Property()
title!: string;
// اضافه شد
@Property({ default: 'general' })
group!: string;
@ManyToMany({ entity: () => Role, mappedBy: 'permissions' })
roles = new Collection<Role>(this);
+1 -11
View File
@@ -17,7 +17,7 @@ export class RolesService {
@InjectRepository(Permission)
private readonly permissionRepository: EntityRepository<Permission>,
private readonly em: EntityManager,
) {}
) { }
async createRestaurantRole(dto: CreateRoleDto, restId: string) {
const { name, permissionIds } = dto;
@@ -48,11 +48,6 @@ export class RolesService {
if (permissions.length !== permissionIds.length) {
throw new BadRequestException('One or more permissions not found');
}
// Check if any permission is special
const specialPermissions = permissions.filter(p => p.group === 'special');
if (specialPermissions.length > 0) {
throw new BadRequestException('Special permissions cannot be assigned');
}
permissions.forEach(p => role.permissions.add(p));
}
@@ -102,11 +97,6 @@ export class RolesService {
if (permissions.length !== dto.permissionIds.length) {
throw new BadRequestException('One or more permissions not found');
}
// Check if any permission is special
const specialPermissions = permissions.filter(p => p.group === 'special');
if (specialPermissions.length > 0) {
throw new BadRequestException('Special permissions cannot be assigned to roles');
}
permissions.forEach(p => role.permissions.add(p));
}