Files
dmenu-api/src/seeders/restaurants.seeder.ts
T
2025-12-31 15:36:25 +03:30

27 lines
899 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,
});
em.persist(restaurant);
}
restaurantsMap.set(restaurantData.slug, restaurant);
}
await em.flush();
return restaurantsMap;
}
}