This commit is contained in:
2025-12-03 23:41:24 +03:30
parent 2248f18fe8
commit 87e935acfd
21 changed files with 1002 additions and 755 deletions
+22
View File
@@ -0,0 +1,22 @@
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);
em.persist(restaurant);
}
restaurantsMap.set(restaurantData.slug, restaurant);
}
await em.flush();
return restaurantsMap;
}
}