This commit is contained in:
2025-12-06 23:09:01 +03:30
parent 6c62c8badc
commit 7567e00f8a
2 changed files with 5 additions and 10 deletions
@@ -15,6 +15,7 @@ export class AdminRepository extends EntityRepository<Admin> {
} }
async findByPhoneAndRestaurantSlug(phone: string, slug: string): Promise<Admin | null> { async findByPhoneAndRestaurantSlug(phone: string, slug: string): Promise<Admin | null> {
console.log('phone', phone);
const normalizedPhone = normalizePhone(phone); const normalizedPhone = normalizePhone(phone);
// First, find the restaurant by slug using the same repository as auth service // First, find the restaurant by slug using the same repository as auth service
const restaurant = await this.restRepository.findOne({ slug }); const restaurant = await this.restRepository.findOne({ slug });
+4 -10
View File
@@ -4,13 +4,10 @@ import { AdminRole } from '../modules/admin/entities/adminRole.entity';
import { Role } from '../modules/roles/entities/role.entity'; import { Role } from '../modules/roles/entities/role.entity';
import { Restaurant } from '../modules/restaurants/entities/restaurant.entity'; import { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
import { adminsData } from './data/admins.data'; import { adminsData } from './data/admins.data';
import { normalizePhone } from '../modules/utils/phone.util';
export class AdminsSeeder { export class AdminsSeeder {
async run( async run(em: EntityManager, rolesMap: Map<string, Role>, restaurantsMap: Map<string, Restaurant>): Promise<void> {
em: EntityManager,
rolesMap: Map<string, Role>,
restaurantsMap: Map<string, Restaurant>,
): Promise<void> {
for (const adminData of adminsData) { for (const adminData of adminsData) {
const existingAdmin = await em.findOne(Admin, { phone: adminData.phone }); const existingAdmin = await em.findOne(Admin, { phone: adminData.phone });
if (existingAdmin) continue; if (existingAdmin) continue;
@@ -18,15 +15,13 @@ export class AdminsSeeder {
const role = rolesMap.get(adminData.roleName); const role = rolesMap.get(adminData.roleName);
if (!role) continue; if (!role) continue;
const restaurant = adminData.restaurantSlug const restaurant = adminData.restaurantSlug ? restaurantsMap.get(adminData.restaurantSlug) : null;
? restaurantsMap.get(adminData.restaurantSlug)
: null;
// For restaurant role, restaurant is required // For restaurant role, restaurant is required
if (adminData.roleName === 'restaurant' && !restaurant) continue; if (adminData.roleName === 'restaurant' && !restaurant) continue;
const admin = em.create(Admin, { const admin = em.create(Admin, {
phone: adminData.phone, phone: normalizePhone(adminData.phone),
firstName: adminData.firstName, firstName: adminData.firstName,
lastName: adminData.lastName, lastName: adminData.lastName,
}); });
@@ -45,4 +40,3 @@ export class AdminsSeeder {
await em.flush(); await em.flush();
} }
} }