fix issue

This commit is contained in:
Marshal
2026-07-31 12:23:41 +00:00
parent 8b9dd76710
commit 7e85c16141
5 changed files with 318 additions and 465 deletions

View File

@@ -83,6 +83,11 @@ export class BookingJourneyService {
loadedByUserId: userId ?? null,
} as never);
await this.setAllocationStatuses(manager, scheduleId, bookingId, 'LOADED');
// Keep the schedule↔booking link's tracking flag in sync — the dispatch
// readiness warnings and workspace badges read loading_status, not loadedAt.
await manager
.getRepository(TrainScheduleBooking)
.update({ trainScheduleId: scheduleId, bookingId }, { loadingStatus: 'LOADED' });
// The facility handed the cargo over — raise its GRN. No-ops for yards
// without a facility (import/export terminals), which keep their own flow.
await this.facilityHandling.recordHandling(manager, {
@@ -236,7 +241,10 @@ export class BookingJourneyService {
return {
scheduleId,
scheduleStatus: schedule.status,
trainAtYardId: latest?.yardId ?? (schedule.status === 'DISPATCHED' ? null : schedule.originStationId),
// No checkpoint yet ⇒ the train is still at its origin, even just after
// dispatch — assertTrainAtYard allows origin loading in that state, so
// the UI position must agree or origin Load buttons grey out wrongly.
trainAtYardId: latest?.yardId ?? schedule.originStationId,
yards: [...byYard.values()],
};
}

View File

@@ -1977,6 +1977,16 @@ export class TrainSchedulingService {
manager,
);
// Unassign only runs pre-dispatch, so an IN_TRANSIT status here is stale
// (e.g. auto-loaded by an earlier dispatch that was rolled back). Left as
// is, the booking becomes invisible: the eligible pool only admits PAID,
// so it can never be re-added to any train. Revert it to PAID.
if (booking?.status === 'IN_TRANSIT' && !booking.arrivedAt) {
await manager
.getRepository(Booking)
.update(bookingId, { status: 'PAID', loadedAt: null } as never);
}
// Recompute the train-set composition from whatever survives this removal.
// The removed booking's allocations were already deleted above, so any slot
// left with zero allocations was ridden only by this booking — release it