mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
update train scheduling logic to clear trainScheduleId when unassigning bookings
This commit is contained in:
@@ -1269,7 +1269,12 @@ export class BookingsRepository extends BaseRepository<Booking> {
|
||||
fields: Partial<
|
||||
Pick<
|
||||
Booking,
|
||||
'schedulingStatus' | 'wagonsRequired' | 'scheduledAt' | 'holdStartedAt' | 'holdExpiresAt'
|
||||
| 'schedulingStatus'
|
||||
| 'wagonsRequired'
|
||||
| 'scheduledAt'
|
||||
| 'holdStartedAt'
|
||||
| 'holdExpiresAt'
|
||||
| 'trainScheduleId'
|
||||
>
|
||||
>,
|
||||
manager?: EntityManager,
|
||||
|
||||
@@ -1387,9 +1387,13 @@ export class TrainSchedulingService {
|
||||
|
||||
const booking = await this.bookingsRepository.findById(bookingId);
|
||||
const schedulingStatus = this.resolvePostUnassignStatus(booking);
|
||||
// Clear the schedule pointer too: unassign fully detaches the booking from
|
||||
// this train. Leaving trainScheduleId set glued the booking to a schedule
|
||||
// that may then be dispatched/cancelled/deleted, orphaning it — the
|
||||
// assign-bookings parity guard would reject it from every OTHER schedule.
|
||||
await this.bookingsRepository.updateSchedulingFields(
|
||||
bookingId,
|
||||
{ schedulingStatus, wagonsRequired: null },
|
||||
{ schedulingStatus, wagonsRequired: null, trainScheduleId: null },
|
||||
manager,
|
||||
);
|
||||
|
||||
@@ -3043,9 +3047,15 @@ export class TrainSchedulingService {
|
||||
}
|
||||
for (const sb of schedule.scheduleBookings ?? []) {
|
||||
const booking = await this.bookingsRepository.findById(sb.bookingId);
|
||||
// Detach from the cancelled schedule — clear the pointer so the freed
|
||||
// booking can be assigned to another train. Leaving it set orphans the
|
||||
// booking against a schedule that is about to be gone.
|
||||
await this.bookingsRepository.updateSchedulingFields(
|
||||
sb.bookingId,
|
||||
{ schedulingStatus: this.resolvePostUnassignStatus(booking) },
|
||||
{
|
||||
schedulingStatus: this.resolvePostUnassignStatus(booking),
|
||||
trainScheduleId: null,
|
||||
},
|
||||
manager,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user