mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 13:05:44 +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<
|
fields: Partial<
|
||||||
Pick<
|
Pick<
|
||||||
Booking,
|
Booking,
|
||||||
'schedulingStatus' | 'wagonsRequired' | 'scheduledAt' | 'holdStartedAt' | 'holdExpiresAt'
|
| 'schedulingStatus'
|
||||||
|
| 'wagonsRequired'
|
||||||
|
| 'scheduledAt'
|
||||||
|
| 'holdStartedAt'
|
||||||
|
| 'holdExpiresAt'
|
||||||
|
| 'trainScheduleId'
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
manager?: EntityManager,
|
manager?: EntityManager,
|
||||||
|
|||||||
@@ -1387,9 +1387,13 @@ export class TrainSchedulingService {
|
|||||||
|
|
||||||
const booking = await this.bookingsRepository.findById(bookingId);
|
const booking = await this.bookingsRepository.findById(bookingId);
|
||||||
const schedulingStatus = this.resolvePostUnassignStatus(booking);
|
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(
|
await this.bookingsRepository.updateSchedulingFields(
|
||||||
bookingId,
|
bookingId,
|
||||||
{ schedulingStatus, wagonsRequired: null },
|
{ schedulingStatus, wagonsRequired: null, trainScheduleId: null },
|
||||||
manager,
|
manager,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -3043,9 +3047,15 @@ export class TrainSchedulingService {
|
|||||||
}
|
}
|
||||||
for (const sb of schedule.scheduleBookings ?? []) {
|
for (const sb of schedule.scheduleBookings ?? []) {
|
||||||
const booking = await this.bookingsRepository.findById(sb.bookingId);
|
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(
|
await this.bookingsRepository.updateSchedulingFields(
|
||||||
sb.bookingId,
|
sb.bookingId,
|
||||||
{ schedulingStatus: this.resolvePostUnassignStatus(booking) },
|
{
|
||||||
|
schedulingStatus: this.resolvePostUnassignStatus(booking),
|
||||||
|
trainScheduleId: null,
|
||||||
|
},
|
||||||
manager,
|
manager,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user