🛡️ Safety: Prevent self-deactivation and fix staff UI

This commit is contained in:
Hamza-Ayed
2026-04-19 15:54:50 +03:00
parent ff8126f93b
commit 6b9ce6e95b
3 changed files with 16 additions and 9 deletions

View File

@@ -44,6 +44,6 @@ export class UsersController {
@Delete(':id')
@Roles(UserRole.ADMIN)
async remove(@CurrentUser() user: any, @Param('id') id: string) {
return this.usersService.remove(user.tenantId, id);
return this.usersService.remove(user.tenantId, id, user.id);
}
}

View File

@@ -64,7 +64,10 @@ export class UsersService {
/**
* تعطيل مستخدم
*/
async remove(tenantId: string, id: string): Promise<void> {
async remove(tenantId: string, id: string, currentUserId: string): Promise<void> {
if (id === currentUserId) {
throw new ConflictException('لا يمكنك تعطيل حسابك الشخصي');
}
const user = await this.findOne(tenantId, id);
await this.userRepository.update(id, { is_active: false });
}