This commit is contained in:
natib21
2026-07-03 19:17:45 +00:00
parent 2550172480
commit a1dfb439ff
9 changed files with 289 additions and 131 deletions

View File

@@ -3,6 +3,7 @@ import { WagonStatus } from '@edr/types';
import { DataSource } from 'typeorm';
import { Booking } from '../modules/bookings/entities/booking.entity';
import { Company } from '../modules/companies/entities/company.entity';
import { Locomotive } from '../modules/locomotives/entities/locomotive.entity';
import { CargoType } from '../modules/rule-engine/entities/cargo-type.entity';
import { ServiceType } from '../modules/rule-engine/entities/service-type.entity';
@@ -116,6 +117,11 @@ export class MarshallingDemoTrainsSeeder {
? await warehouseZoneRepo.findOne({ where: { yardId: warehouseYard.id } })
: null;
// bookings.company_id is NOT NULL — reuse any seeded company for the demo.
const company = await this.dataSource
.getRepository(Company)
.findOne({ where: {}, order: { createdAt: 'ASC' } });
const missing = [
!djiboutiYard ? 'Djibouti yard' : '',
!ethiopiaYard ? 'Ethiopia yard' : '',
@@ -124,6 +130,7 @@ export class MarshallingDemoTrainsSeeder {
!warehouse ? 'INDODE_OPEN warehouse' : '',
!warehouseYard ? 'warehouse yard' : '',
!warehouseZone ? 'warehouse zone' : '',
!company ? 'company' : '',
].filter(Boolean);
if (missing.length) {
this.logger.warn(`Cannot seed marshalling demo trains, missing: ${missing.join(', ')}`);
@@ -141,6 +148,7 @@ export class MarshallingDemoTrainsSeeder {
warehouse: warehouse!,
warehouseYard: warehouseYard!,
warehouseZone: warehouseZone!,
company: company!,
});
if (created) seeded += 1;
}
@@ -164,6 +172,7 @@ export class MarshallingDemoTrainsSeeder {
warehouse: Warehouse;
warehouseYard: WarehouseYard;
warehouseZone: WarehouseZone;
company: Company;
},
): Promise<boolean> {
const bookingRepo = this.dataSource.getRepository(Booking);
@@ -231,6 +240,7 @@ export class MarshallingDemoTrainsSeeder {
const booking = await bookingRepo.save(
bookingRepo.create({
reference: bookingReference,
companyId: refs.company.id,
originYardId: originYard.id,
destinationYardId: destinationYard.id,
serviceTypeId: refs.serviceType.id,