update seeder
This commit is contained in:
@@ -38,6 +38,7 @@ export class FoodService {
|
||||
breakfast: rest.breakfast ?? false,
|
||||
noon: rest.noon ?? false,
|
||||
dinner: rest.dinner ?? false,
|
||||
desc: rest.desc,
|
||||
// pickup/stock
|
||||
stock: rest.stock ?? 0,
|
||||
stockDefault: rest.stockDefault ?? 0,
|
||||
@@ -54,7 +55,7 @@ export class FoodService {
|
||||
prepareTime: rest.prepareTime ?? 0,
|
||||
images: rest.images ?? undefined,
|
||||
restaurant: restaurant,
|
||||
category: category
|
||||
category: category,
|
||||
};
|
||||
|
||||
const food = this.foodRepository.create(data);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Permission, PermissionTitles } from '../common/enums/permission.enum';
|
||||
import { PaymentMethod } from '../modules/payments/entities/payment-method.entity';
|
||||
import { RestaurantPaymentMethod } from '../modules/payments/entities/restaurant-payment-method.entity';
|
||||
import { ShipmentMethod } from '../modules/shipments/entities/shipment-method.entity';
|
||||
import { Schedule } from '../modules/restaurants/entities/schedule.entity';
|
||||
|
||||
export class DatabaseSeeder extends Seeder {
|
||||
async run(em: EntityManager) {
|
||||
@@ -233,6 +234,47 @@ export class DatabaseSeeder extends Seeder {
|
||||
|
||||
await em.flush();
|
||||
|
||||
// 5.6. Create Schedules for all Restaurants
|
||||
// For each restaurant, create 3 schedules per day (breakfast, lunch, dinner) for all 7 days
|
||||
const allRestaurantsForSchedules = await em.find(Restaurant, {});
|
||||
|
||||
// Define three time slots per day
|
||||
const timeSlots = [
|
||||
{ openTime: '08:00', closeTime: '11:00' }, // Breakfast
|
||||
{ openTime: '12:00', closeTime: '15:00' }, // Lunch
|
||||
{ openTime: '18:00', closeTime: '23:00' }, // Dinner
|
||||
];
|
||||
|
||||
for (const restaurant of allRestaurantsForSchedules) {
|
||||
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();
|
||||
|
||||
// 6. Create Categories (Farsi)
|
||||
const categories = [
|
||||
{ title: 'غذای اصلی', restaurant: zhivan },
|
||||
|
||||
Reference in New Issue
Block a user