diff --git a/apps/edr-freight-api/src/modules/routes/entities/route.entity.ts b/apps/edr-freight-api/src/modules/routes/entities/route.entity.ts index 23399bb4d..238129a1d 100644 --- a/apps/edr-freight-api/src/modules/routes/entities/route.entity.ts +++ b/apps/edr-freight-api/src/modules/routes/entities/route.entity.ts @@ -43,11 +43,26 @@ export class Route extends BaseEntity { * Human-readable route label: yard names, not yard codes — "Addis Ababa → Dire Dawa", * not "ADDIS_ABABA → DIRE_DAWA". A yard's display name is its `label`; `code` is the * machine identifier and is only a fallback for a yard missing one. + * + * When the route's milestones are loaded (with their yards), the label is the FULL + * ordered corridor — "Addis Ababa → Adama → Dire Dawa" — since milestones already + * include the origin (first) and destination (last). Without milestones it falls + * back to origin → destination. */ export function formatRouteLabel(route: { originYard?: { code?: string; label?: string } | null; destinationYard?: { code?: string; label?: string } | null; + milestones?: Array<{ + sequenceNo: number; + yard?: { code?: string; label?: string } | null; + }> | null; }): string { + const stops = [...(route.milestones ?? [])] + .sort((a, b) => a.sequenceNo - b.sequenceNo) + .map((m) => m.yard?.label ?? m.yard?.code) + .filter((name): name is string => Boolean(name)); + if (stops.length >= 2) return stops.join(' → '); + const origin = route.originYard?.label ?? route.originYard?.code ?? 'Origin'; const dest = route.destinationYard?.label ?? route.destinationYard?.code ?? 'Destination'; return `${origin} → ${dest}`; diff --git a/apps/edr-freight-api/src/modules/train-schedules/train-schedules.repository.ts b/apps/edr-freight-api/src/modules/train-schedules/train-schedules.repository.ts index a64faabbe..6a8aced53 100644 --- a/apps/edr-freight-api/src/modules/train-schedules/train-schedules.repository.ts +++ b/apps/edr-freight-api/src/modules/train-schedules/train-schedules.repository.ts @@ -23,8 +23,9 @@ export class TrainSchedulesRepository extends BaseRepository { where: { id }, relations: { // Yards carry the route's display name; without them formatRouteLabel - // degrades to the literal "Origin → Destination". - route: { originYard: true, destinationYard: true }, + // degrades to the literal "Origin → Destination". Milestones (with + // their yards) give it the full corridor path. + route: { originYard: true, destinationYard: true, milestones: { yard: true } }, trainSet: { locomotive: true, locomotives: { locomotive: true }, diff --git a/apps/edr-freight-api/src/modules/train-scheduling/booking-batch.service.ts b/apps/edr-freight-api/src/modules/train-scheduling/booking-batch.service.ts index 5609c8801..0e6f1fd8c 100644 --- a/apps/edr-freight-api/src/modules/train-scheduling/booking-batch.service.ts +++ b/apps/edr-freight-api/src/modules/train-scheduling/booking-batch.service.ts @@ -746,8 +746,9 @@ export class BookingBatchService implements OnModuleInit { trainSet: { locomotive: true }, originStation: true, destinationStation: true, - // Yards supply the route's display name for `routeName` below. - route: { originYard: true, destinationYard: true }, + // Yards supply the route's display name for `routeName` below; + // milestones (with yards) give it the full corridor path. + route: { originYard: true, destinationYard: true, milestones: { yard: true } }, }, order: { [sortBy]: sortOrder } as never, skip: (page - 1) * pageSize, 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 0fbfd30ce..eee880a6b 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 @@ -2645,8 +2645,9 @@ export class TrainSchedulingService { const schedules = await this.trainSchedulesRepository.findAll({ relations: { trainSet: { locomotive: true, locomotives: { locomotive: true } }, - // Yards carry the route's display name used by mapScheduleListItem. - route: { originYard: true, destinationYard: true }, + // Yards carry the route's display name used by mapScheduleListItem; + // milestones (with yards) let it show the full corridor path. + route: { originYard: true, destinationYard: true, milestones: { yard: true } }, originStation: true, destinationStation: true, scheduleBookings: { booking: true },