init
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import type { EntityManager } from '@mikro-orm/core';
|
||||
import { Schedule } from '../modules/restaurants/entities/schedule.entity';
|
||||
import type { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
||||
import { timeSlots } from './data/schedules.data';
|
||||
|
||||
export class SchedulesSeeder {
|
||||
async run(em: EntityManager, restaurants: Restaurant[]): Promise<void> {
|
||||
for (const restaurant of restaurants) {
|
||||
if (!restaurant) continue;
|
||||
|
||||
// Create schedules for each day (0 = Sunday, 6 = Saturday)
|
||||
for (let weekDay = 0; weekDay <= 6; weekDay++) {
|
||||
// Create 3 schedules per day
|
||||
for (const timeSlot of timeSlots) {
|
||||
const existing = await em.findOne(Schedule, {
|
||||
restId: restaurant.id,
|
||||
weekDay,
|
||||
openTime: timeSlot.openTime,
|
||||
closeTime: timeSlot.closeTime,
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
const schedule = em.create(Schedule, {
|
||||
restId: restaurant.id,
|
||||
weekDay,
|
||||
openTime: timeSlot.openTime,
|
||||
closeTime: timeSlot.closeTime,
|
||||
isActive: true,
|
||||
});
|
||||
em.persist(schedule);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await em.flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user