update role
This commit is contained in:
@@ -7,11 +7,6 @@ export class CreateRoleDto {
|
||||
@IsString()
|
||||
name!: string;
|
||||
|
||||
@ApiProperty({ description: 'Role title' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
title!: string;
|
||||
|
||||
|
||||
@ApiProperty({ description: 'List of permission IDs', isArray: true, required: false })
|
||||
@IsOptional()
|
||||
|
||||
@@ -7,11 +7,6 @@ export class UpdateRoleDto {
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@ApiProperty({ description: 'Role title', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
title?: string;
|
||||
|
||||
@ApiProperty({ description: 'List of permission IDs', isArray: true, required: false })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
|
||||
@@ -11,9 +11,6 @@ export class Role extends BaseEntity {
|
||||
@Property()
|
||||
name!: string;
|
||||
|
||||
@Property()
|
||||
title!: string;
|
||||
|
||||
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
||||
permissions = new Collection<Permission>(this);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export class RolesService {
|
||||
) {}
|
||||
|
||||
async create(restId: string, dto: CreateRoleDto) {
|
||||
const { name, title, permissionIds } = dto;
|
||||
const { name, permissionIds } = dto;
|
||||
|
||||
// Check if role already exists
|
||||
const existing = await this.roleRepository.findOne({ name, restaurant: restId ? { id: restId } : null });
|
||||
@@ -39,7 +39,6 @@ export class RolesService {
|
||||
|
||||
const role = this.roleRepository.create({
|
||||
name,
|
||||
title,
|
||||
restaurant,
|
||||
});
|
||||
|
||||
@@ -75,11 +74,11 @@ export class RolesService {
|
||||
populate: ['permissions', 'restaurant'],
|
||||
});
|
||||
|
||||
// Filter by name or title in memory if provided
|
||||
// Filter by name in memory if provided
|
||||
let filtered = roles;
|
||||
if (name) {
|
||||
filtered = roles.filter(
|
||||
r => r.name.toLowerCase().includes(name.toLowerCase()) || r.title.toLowerCase().includes(name.toLowerCase()),
|
||||
r => r.name.toLowerCase().includes(name.toLowerCase()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,10 +115,6 @@ export class RolesService {
|
||||
role.name = dto.name;
|
||||
}
|
||||
|
||||
if (dto.title) {
|
||||
role.title = dto.title;
|
||||
}
|
||||
|
||||
if (dto.permissionIds && dto.permissionIds.length >= 0) {
|
||||
// Clear existing permissions and add new ones
|
||||
role.permissions.removeAll();
|
||||
|
||||
Reference in New Issue
Block a user