From fac601030c6f22f949e6dfc50d27ef1d1f39f2f3 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 5 Feb 2026 11:24:20 +0330 Subject: [PATCH] admin --- .../admin/controllers/admin.controller.ts | 4 ---- src/modules/admin/providers/admin.service.ts | 8 ++++---- src/modules/roles/providers/roles.service.ts | 2 +- src/seeders/data/admins.data.ts | 17 ++++++++--------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/modules/admin/controllers/admin.controller.ts b/src/modules/admin/controllers/admin.controller.ts index f933811..ed2750f 100644 --- a/src/modules/admin/controllers/admin.controller.ts +++ b/src/modules/admin/controllers/admin.controller.ts @@ -42,22 +42,18 @@ export class AdminController { @Patch('admin/admins/:adminId') @ApiOperation({ summary: 'Update an admin' }) - @ApiParam({ name: 'adminId', description: 'Admin ID' }) - @ApiBody({ type: UpdateAdminDto }) update(@Param('adminId') adminId: string, @Body() dto: UpdateAdminDto,): Promise { return this.adminService.update(adminId, dto); } @Get('admin/admins/:adminId') @ApiOperation({ summary: 'Get an admin by ID' }) - @ApiParam({ name: 'id', description: 'Admin ID' }) getById(@Param('adminId') adminId: string,): Promise { return this.adminService.findById(adminId,); } @Delete('admin/admins/:adminId') @ApiOperation({ summary: 'Delete an admin by ID' }) - @ApiParam({ name: 'id', description: 'Admin ID' }) deleteById(@Param('adminId') adminId: string,): Promise { return this.adminService.softDelete(adminId,); } diff --git a/src/modules/admin/providers/admin.service.ts b/src/modules/admin/providers/admin.service.ts index 685cf1a..38edf04 100644 --- a/src/modules/admin/providers/admin.service.ts +++ b/src/modules/admin/providers/admin.service.ts @@ -25,14 +25,14 @@ export class AdminService { const currentAdmin = await this.adminRepository.findOne({ phone: normalizedPhone, - }); + }, { filters: { notDeleted: false } }); if (currentAdmin && !currentAdmin.deletedAt) { throw new BadRequestException('This phone number is already used'); } - //TODO : test admins that were delted - // re-register deleted admin + + // retrieve deleted admin if (currentAdmin && currentAdmin.deletedAt) { currentAdmin.deletedAt = undefined await this.em.flush() @@ -74,7 +74,7 @@ export class AdminService { async findById(adminId: string): Promise { const admin = await this.adminRepository.findOne( { id: adminId }, - { populate: ['role'] }, + { populate: ['role', 'role.permissions'] }, ); return admin; } diff --git a/src/modules/roles/providers/roles.service.ts b/src/modules/roles/providers/roles.service.ts index 543a731..4154a74 100644 --- a/src/modules/roles/providers/roles.service.ts +++ b/src/modules/roles/providers/roles.service.ts @@ -47,7 +47,7 @@ export class RolesService { } async findAll() { - const where: FilterQuery = { isSystem: false }; + const where: FilterQuery = {}; const roles = await this.roleRepository.find(where, { orderBy: { createdAt: 'desc' }, diff --git a/src/seeders/data/admins.data.ts b/src/seeders/data/admins.data.ts index c2d394a..c38e86d 100644 --- a/src/seeders/data/admins.data.ts +++ b/src/seeders/data/admins.data.ts @@ -3,7 +3,6 @@ export interface AdminData { firstName: string; lastName: string; roleName: string; - restaurantSlug: string | null; } export const adminsData: AdminData[] = [ @@ -12,27 +11,27 @@ export const adminsData: AdminData[] = [ firstName: 'مرتضی', lastName: 'مرتضایی', roleName: 'admin', - restaurantSlug: 'boote', + }, { phone: '09185290775', firstName: 'حمید', lastName: 'ضرقامی', roleName: 'admin', - restaurantSlug: 'boote', + }, { phone: '09129283395', firstName: 'مهرداد', lastName: 'مظفری', - roleName: 'admin', - restaurantSlug: 'boote', + roleName: 'designer', + }, { phone: '09184317567', - firstName: 'ادمین', - lastName: 'هنر', - roleName: 'admin', - restaurantSlug: 'boote', + firstName: 'حسابداری', + lastName: 'ح', + roleName: 'accountant', + }, ];