Implement 'getMe' endpoint in AdminController to retrieve current admin details; update AdminService to return transformed admin details and adjust findById method for improved data handling. Remove unused user profile retrieval method from AdminUserController.
This commit is contained in:
@@ -6,6 +6,7 @@ import { Role } from '../entities/role.entity';
|
||||
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { CacheService } from '../../utils/cache.service';
|
||||
import { AdminDetailTransformer, AdminDetailResponse } from '../transformers/admin-detail.transformer';
|
||||
|
||||
@Injectable()
|
||||
export class AdminService {
|
||||
@@ -22,8 +23,14 @@ export class AdminService {
|
||||
return this.adminRepository.findOne({ phone });
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<Admin | null> {
|
||||
return this.adminRepository.findOne({ id });
|
||||
async findById(id: string): Promise<AdminDetailResponse | null> {
|
||||
const admin = await this.adminRepository.findOne({ id }, { populate: ['role', 'role.permissions', 'restaurant'] });
|
||||
|
||||
if (!admin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return AdminDetailTransformer.transform(admin);
|
||||
}
|
||||
async findAll(): Promise<Admin[]> {
|
||||
return this.adminRepository.findAll();
|
||||
@@ -63,7 +70,7 @@ export class AdminService {
|
||||
const cachedPermissions = await this.cacheService.get<string>(cacheKey);
|
||||
if (cachedPermissions) {
|
||||
try {
|
||||
const parsed = JSON.parse(cachedPermissions);
|
||||
const parsed: unknown = JSON.parse(cachedPermissions);
|
||||
// Ensure it's an array of strings
|
||||
if (Array.isArray(parsed) && parsed.every((p): p is string => typeof p === 'string')) {
|
||||
return parsed;
|
||||
|
||||
Reference in New Issue
Block a user