mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-31 09:37:38 +00:00
fix: don't block import train dispatch on loading confirmation
Loading (loaded-on-train step + per-booking loading status) no longer gates dispatch/departure of a Djibouti import train. Per-booking loading status stays tracking-only; a scheduled train dispatches once gatepass is granted, without waiting on loading confirmation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1207,11 +1207,7 @@ export class TrainSchedulingService {
|
|||||||
const schedule = await this.getImportDjiboutiSchedule(scheduleId);
|
const schedule = await this.getImportDjiboutiSchedule(scheduleId);
|
||||||
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
||||||
this.assertImportDjiboutiGatepassGranted(operation);
|
this.assertImportDjiboutiGatepassGranted(operation);
|
||||||
if (!operation.loadedOnTrainAt && !(await this.hasLoadedBooking(schedule.id))) {
|
// Loading confirmation does not block departure (see assertImportDjiboutiMayDepart).
|
||||||
throw new BadRequestException(
|
|
||||||
'Import train cannot depart Djibouti before at least one booking is loaded',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (schedule.status === TrainScheduleStatusEnum.Scheduled) {
|
if (schedule.status === TrainScheduleStatusEnum.Scheduled) {
|
||||||
await this.dispatchSchedule(schedule.id);
|
await this.dispatchSchedule(schedule.id);
|
||||||
@@ -1588,26 +1584,9 @@ export class TrainSchedulingService {
|
|||||||
where: { trainScheduleId: schedule.id },
|
where: { trainScheduleId: schedule.id },
|
||||||
});
|
});
|
||||||
this.assertImportDjiboutiGatepassGranted(operation);
|
this.assertImportDjiboutiGatepassGranted(operation);
|
||||||
// A train dispatches once loading is confirmed at the train level OR at least
|
// Loading confirmation does NOT gate dispatch. Per-booking loading is
|
||||||
// one booking on it is marked LOADED — it never waits for every booking.
|
// tracking only and the loaded-on-train step is optional — a scheduled train
|
||||||
if (!operation?.loadedOnTrainAt && !(await this.hasLoadedBooking(schedule.id))) {
|
// dispatches without waiting on loading.
|
||||||
throw new BadRequestException(
|
|
||||||
'Import train cannot depart Djibouti before at least one booking is loaded',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** True when at least one booking on the schedule is confirmed LOADED. */
|
|
||||||
private async hasLoadedBooking(scheduleId: string): Promise<boolean> {
|
|
||||||
const [row]: Array<{ loaded: string }> = await this.dataSource.query(
|
|
||||||
`SELECT COUNT(*) AS loaded
|
|
||||||
FROM freight.train_schedule_bookings
|
|
||||||
WHERE train_schedule_id = $1
|
|
||||||
AND loading_status = $2
|
|
||||||
AND deleted_at IS NULL`,
|
|
||||||
[scheduleId, LoadingStatus.Loaded],
|
|
||||||
);
|
|
||||||
return Number(row?.loaded ?? 0) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getImportDjiboutiSchedule(scheduleId: string): Promise<TrainSchedule> {
|
private async getImportDjiboutiSchedule(scheduleId: string): Promise<TrainSchedule> {
|
||||||
|
|||||||
Reference in New Issue
Block a user