From 1ce41cdddeb0e5d539ac46498aa8e6bd5ac7c945 Mon Sep 17 00:00:00 2001 From: hagiye Date: Fri, 5 Jun 2026 10:46:08 +0300 Subject: [PATCH] Fix train scheduling and booking seeder --- .../train-scheduling/train-scheduling.service.ts | 12 ++++++------ .../edr-freight-api/src/seed/demo-bookings.seeder.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/edr-freight-api/src/modules/train-scheduling/train-scheduling.service.ts b/apps/edr-freight-api/src/modules/train-scheduling/train-scheduling.service.ts index 2a337afef..095ade158 100644 --- a/apps/edr-freight-api/src/modules/train-scheduling/train-scheduling.service.ts +++ b/apps/edr-freight-api/src/modules/train-scheduling/train-scheduling.service.ts @@ -80,7 +80,7 @@ export class TrainSchedulingService { const bookingRepository = this.dataSource.getRepository(Booking); const queryBuilder = bookingRepository .createQueryBuilder('booking') - .leftJoinAndSelect('booking.customer', 'customer') + .leftJoinAndSelect('booking.company', 'company') .leftJoinAndSelect('booking.originYard', 'originYard') .leftJoinAndSelect('booking.destinationYard', 'destinationYard') .leftJoinAndSelect('booking.bookingContainers', 'bookingContainer') @@ -120,7 +120,7 @@ export class TrainSchedulingService { const items: EligibleBookingItem[] = bookings.map((booking) => ({ id: booking.id, reference: booking.reference, - customer: booking.customer?.companyName ?? booking.customer?.email ?? 'Unknown customer', + customer: booking.company?.name ?? booking.company?.email ?? 'Unknown customer', containerType: booking.bookingContainers ?.map((container) => container.containerType?.label ?? container.containerType?.code ?? 'Container') .join(', ') ?? 'Container', @@ -550,7 +550,7 @@ export class TrainSchedulingService { trainSet: { locomotive: true, wagons: { wagonType: true, allocations: { booking: true } } }, originStation: true, destinationStation: true, - scheduleBookings: { booking: { customer: true, originYard: true, destinationYard: true } }, + scheduleBookings: { booking: { company: true, originYard: true, destinationYard: true } }, }, }); @@ -614,8 +614,8 @@ export class TrainSchedulingService { id: scheduleBooking.booking?.id ?? scheduleBooking.bookingId, reference: scheduleBooking.booking?.reference ?? null, customer: - scheduleBooking.booking?.customer?.companyName ?? - scheduleBooking.booking?.customer?.email ?? + scheduleBooking.booking?.company?.name ?? + scheduleBooking.booking?.company?.email ?? null, weightTons: this.roundTons(Number(scheduleBooking.booking?.cargoTotalWeightVgm ?? 0)), status: scheduleBooking.booking?.status ?? null, @@ -658,7 +658,7 @@ export class TrainSchedulingService { return this.dataSource.getRepository(Booking).find({ where: { id: In(bookingIds) }, relations: { - customer: true, + company: true, originYard: true, destinationYard: true, bookingContainers: { containerType: true }, diff --git a/apps/edr-freight-api/src/seed/demo-bookings.seeder.ts b/apps/edr-freight-api/src/seed/demo-bookings.seeder.ts index 507040eb0..7ad865c4e 100644 --- a/apps/edr-freight-api/src/seed/demo-bookings.seeder.ts +++ b/apps/edr-freight-api/src/seed/demo-bookings.seeder.ts @@ -4,7 +4,7 @@ import { DataSource } from 'typeorm'; import { BookingContainer } from '../modules/bookings/entities/booking-container.entity'; import { Booking } from '../modules/bookings/entities/booking.entity'; -import { Customer } from '../modules/customers/entities/customer.entity'; +import { Company } from '../modules/companies/entities/company.entity'; import { Locomotive } from '../modules/locomotives/entities/locomotive.entity'; import { ServiceType } from '../modules/rule-engine/entities/service-type.entity'; import { Yard } from '../modules/rule-engine/entities/yard.entity'; @@ -197,7 +197,7 @@ export class DemoBookingsSeeder { { conflictPaths: { email: true } }, ); - const [serviceType, customer, yards, containerTypes] = await Promise.all([ + const [serviceType, company, yards, containerTypes] = await Promise.all([ manager.getRepository(ServiceType).findOneByOrFail({ code: SERVICE_TYPE_CODE }), manager.getRepository(Customer).findOneByOrFail({ email: CUSTOMER_EMAIL }), manager.getRepository(Yard).find(), @@ -223,7 +223,7 @@ export class DemoBookingsSeeder { await manager.getRepository(Booking).upsert( { reference: demoBooking.reference, - customerId: customer.id, + companyId: company.id, status: 'APPROVED', scheduledDate: new Date(demoBooking.scheduledDate), totalAmount: 0,