fix: improve code

This commit is contained in:
Emnaghz 2024-09-23 16:58:19 +01:00
parent d2f61eebcd
commit e93c649115

View File

@ -164,15 +164,11 @@ export class RoleController extends BaseController<
} else if (associatedUser) { } else if (associatedUser) {
throw new ForbiddenException('Role is associated with other users'); throw new ForbiddenException('Role is associated with other users');
} else { } else {
try { const result = await this.roleService.deleteOne(id);
const result = await this.roleService.deleteOne(id); if (result.deletedCount === 0) {
if (result.deletedCount === 0) {
throw new NotFoundException(`Role with ID ${id} not found`);
}
return result;
} catch (error) {
throw new NotFoundException(`Role with ID ${id} not found`); throw new NotFoundException(`Role with ID ${id} not found`);
} }
return result;
} }
} }
} }