fix bug in get one admin
This commit is contained in:
@@ -62,7 +62,7 @@ export class AdminController {
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@ApiOperation({ summary: 'Get an admin by ID' })
|
||||
@ApiParam({ name: 'adminId', description: 'Admin ID' })
|
||||
getById(@Param('adminId') adminId: string, @ShopId() shopId: string): Promise<Admin | null> {
|
||||
getById(@Param('adminId') adminId: string, @ShopId() shopId: string) {
|
||||
return this.adminService.findById(adminId, shopId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BadRequestException, ConflictException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { EntityRepository } from '@mikro-orm/core';
|
||||
import { EntityRepository, wrap } from '@mikro-orm/core';
|
||||
import { Admin } from '../entities/admin.entity';
|
||||
import { Role } from '../../roles/entities/role.entity';
|
||||
import { Shop } from '../../shops/entities/shop.entity';
|
||||
@@ -28,12 +28,19 @@ export class AdminService {
|
||||
return this.adminRepository.findOne({ phone: normalizedPhone });
|
||||
}
|
||||
|
||||
async findById(adminId: string, shopId: string): Promise<Admin | null> {
|
||||
async findById(adminId: string, shopId: string) {
|
||||
const admin = await this.adminRepository.findOne(
|
||||
{ id: adminId, roles: { shop: { id: shopId } } },
|
||||
{ populate: ['roles', 'roles.role'] },
|
||||
);
|
||||
return admin;
|
||||
if (!admin) {
|
||||
throw new NotFoundException('Admin not found');
|
||||
}
|
||||
|
||||
const adminPlain = wrap(admin).toObject();
|
||||
const adminRole = await this.adminRoleRepository.findOne({ admin: admin, shop: { id: shopId } });
|
||||
|
||||
return { ...adminPlain, role: adminRole?.role };
|
||||
}
|
||||
|
||||
async findAllByShopId(shopId: string): Promise<Admin[]> {
|
||||
|
||||
Reference in New Issue
Block a user