big
This commit is contained in:
@@ -15,6 +15,7 @@ export class AdminRepository extends EntityRepository<Admin> {
|
||||
}
|
||||
|
||||
async findByPhoneAndRestaurantSlug(phone: string, slug: string): Promise<Admin | null> {
|
||||
console.log('phone', phone);
|
||||
const normalizedPhone = normalizePhone(phone);
|
||||
// First, find the restaurant by slug using the same repository as auth service
|
||||
const restaurant = await this.restRepository.findOne({ slug });
|
||||
|
||||
@@ -4,13 +4,10 @@ import { AdminRole } from '../modules/admin/entities/adminRole.entity';
|
||||
import { Role } from '../modules/roles/entities/role.entity';
|
||||
import { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
||||
import { adminsData } from './data/admins.data';
|
||||
import { normalizePhone } from '../modules/utils/phone.util';
|
||||
|
||||
export class AdminsSeeder {
|
||||
async run(
|
||||
em: EntityManager,
|
||||
rolesMap: Map<string, Role>,
|
||||
restaurantsMap: Map<string, Restaurant>,
|
||||
): Promise<void> {
|
||||
async run(em: EntityManager, rolesMap: Map<string, Role>, restaurantsMap: Map<string, Restaurant>): Promise<void> {
|
||||
for (const adminData of adminsData) {
|
||||
const existingAdmin = await em.findOne(Admin, { phone: adminData.phone });
|
||||
if (existingAdmin) continue;
|
||||
@@ -18,15 +15,13 @@ export class AdminsSeeder {
|
||||
const role = rolesMap.get(adminData.roleName);
|
||||
if (!role) continue;
|
||||
|
||||
const restaurant = adminData.restaurantSlug
|
||||
? restaurantsMap.get(adminData.restaurantSlug)
|
||||
: null;
|
||||
const restaurant = adminData.restaurantSlug ? restaurantsMap.get(adminData.restaurantSlug) : null;
|
||||
|
||||
// For restaurant role, restaurant is required
|
||||
if (adminData.roleName === 'restaurant' && !restaurant) continue;
|
||||
|
||||
const admin = em.create(Admin, {
|
||||
phone: adminData.phone,
|
||||
phone: normalizePhone(adminData.phone),
|
||||
firstName: adminData.firstName,
|
||||
lastName: adminData.lastName,
|
||||
});
|
||||
@@ -45,4 +40,3 @@ export class AdminsSeeder {
|
||||
await em.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user