This commit is contained in:
2025-11-18 00:20:15 +03:30
parent 607e2ec2cf
commit e2b2a746f7
6 changed files with 102 additions and 12 deletions
@@ -0,0 +1,50 @@
import type { Admin } from '../../admin/entities/admin.entity';
import type { Restaurant } from '../../restaurants/entities/restaurant.entity';
export interface AdminLoginResponse {
id: string;
firstName?: string;
lastName?: string;
phone: string;
role: string;
permissions: string[];
restaurant?: {
id: string;
name: string;
slug: string;
};
}
export class AdminLoginTransformer {
static async transform(admin: Admin, restaurant?: Restaurant): Promise<AdminLoginResponse> {
// Extract role name
const role = admin.role?.name || '';
// Extract permissions - ensure collection is loaded if needed
let permissions: string[] = [];
if (admin.role?.permissions) {
if (admin.role.permissions.isInitialized()) {
permissions = admin.role.permissions.getItems().map(p => p.name);
} else {
await admin.role.permissions.loadItems();
permissions = admin.role.permissions.getItems().map(p => p.name);
}
}
return {
id: admin.id,
firstName: admin.firstName,
lastName: admin.lastName,
phone: admin.phone,
role,
permissions,
restaurant: restaurant
? {
id: restaurant.id,
name: restaurant.name,
slug: restaurant.slug,
}
: undefined,
};
}
}