28 lines
930 B
TypeScript
28 lines
930 B
TypeScript
import type { EntityManager } from '@mikro-orm/core';
|
|
import { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
|
import { restaurantsData } from './data/restaurants.data';
|
|
|
|
export class RestaurantsSeeder {
|
|
async run(em: EntityManager): Promise<Map<string, Restaurant>> {
|
|
const restaurantsMap = new Map<string, Restaurant>();
|
|
|
|
for (const restaurantData of restaurantsData) {
|
|
let restaurant = await em.findOne(Restaurant, { slug: restaurantData.slug });
|
|
if (!restaurant) {
|
|
restaurant = em.create(Restaurant, {
|
|
...restaurantData,
|
|
subscriptionStartDate: new Date('2026-01-01'),
|
|
subscriptionEndDate: new Date('2026-01-07'),
|
|
isActive: true,
|
|
enableAiChat: false,
|
|
});
|
|
em.persist(restaurant);
|
|
}
|
|
restaurantsMap.set(restaurantData.slug, restaurant);
|
|
}
|
|
|
|
await em.flush();
|
|
return restaurantsMap;
|
|
}
|
|
}
|