diff --git a/src/modules/admin/controllers/admin.controller.ts b/src/modules/admin/controllers/admin.controller.ts index 59ac46e..1fd790e 100644 --- a/src/modules/admin/controllers/admin.controller.ts +++ b/src/modules/admin/controllers/admin.controller.ts @@ -81,7 +81,7 @@ export class AdminController { @ApiOperation({ summary: 'Get admins for a specific shop (Super Admin only)' }) @ApiParam({ name: 'shopId', description: 'Shop ID' }) getAdminForRestaurant(@Param('shopId') shopId: string): Promise { - return this.adminService.getShopAdminsBySuperAdmin(shopId); + return this.adminService.findAllByShopId(shopId); } @UseGuards(SuperAdminAuthGuard) diff --git a/src/modules/admin/providers/admin.service.ts b/src/modules/admin/providers/admin.service.ts index 402ce7a..8588bf4 100644 --- a/src/modules/admin/providers/admin.service.ts +++ b/src/modules/admin/providers/admin.service.ts @@ -5,13 +5,12 @@ import { Admin } from '../entities/admin.entity'; import { Role } from '../../roles/entities/role.entity'; import { Shop } from '../../shops/entities/shop.entity'; import { EntityManager } from '@mikro-orm/postgresql'; -import { CacheService } from '../../utils/cache.service'; import { CreateMyShopAdminDto } from '../dto/create-shop-admin.dto'; import { UpdateAdminDto } from '../dto/update-admin.dto'; import { AdminRole } from '../entities/adminRole.entity'; import { normalizePhone } from '../../utils/phone.util'; import { AdminRepository } from '../repositories/admin.repository'; -import { AdminMessage, RoleMessage } from 'src/common/enums/message.enum'; +import { AdminMessage } from 'src/common/enums/message.enum'; @Injectable() export class AdminService { @@ -20,7 +19,6 @@ export class AdminService { @InjectRepository(AdminRole) private readonly adminRoleRepository: EntityRepository, private readonly em: EntityManager, - private readonly cacheService: CacheService, ) { } async findByPhone(phone: string): Promise { @@ -43,9 +41,10 @@ export class AdminService { return { ...adminPlain, role: adminRole?.role }; } - async findAllByShopId(shopId: string): Promise { - return this.adminRepository.find({ roles: { shop: { id: shopId } } }, { populate: ['roles', 'roles.role'] }); - } + // async findAllByShopId(shopId: string): Promise { + // return this.adminRepository.find({ roles: { shop: { id: shopId } } }, + // { populate: ['roles', 'roles.role'], }); + // } async createAdminForShop(shopId: string, dto: CreateMyShopAdminDto) { const { phone, firstName, lastName, roleId } = dto; @@ -134,11 +133,14 @@ export class AdminService { return admin; } - async getShopAdminsBySuperAdmin(shopId: string): Promise { + async findAllByShopId(shopId: string): Promise { const shop = await this.em.findOne(Shop, { id: shopId }); if (!shop) throw new NotFoundException(AdminMessage.SHOP_NOT_FOUND); - return this.adminRepository.find({ roles: { shop: shop } }, { populate: ['roles', 'roles.role'] }); + return this.adminRepository.find({ roles: { shop: shop } }, { + populate: ['roles', 'roles.role'], + populateWhere: { roles: { shop: { id: shopId } } } + }); } async update(adminId: string, shopId: string, dto: UpdateAdminDto): Promise { @@ -230,21 +232,16 @@ export class AdminService { }, }, }, - { populate: ['roles', 'roles.role', 'roles.shop'] }, + { + populate: ['roles', 'roles.role', 'roles.shop'], + populateWhere: { roles: { shop: { slug: shopSlug } } } + }, ); if (!admin) { throw new BadRequestException(AdminMessage.ADMIN_NOT_FOUND); } - // Ensure all roles are populated - // await adminRole.admin.roles.loadItems(); - // for (const role of adminRole.admin.roles.getItems()) { - // if (role.role && role.role.permissions && !role.role.permissions.isInitialized()) { - // await role.role.permissions.loadItems(); - // } - // } - return admin; }