This commit is contained in:
Marshal
2026-07-07 18:40:32 +00:00
parent b57840c907
commit 8addfdf3e2
7 changed files with 529 additions and 74 deletions

View File

@@ -1057,6 +1057,43 @@ export class BookingsRepository extends BaseRepository<Booking> {
.getMany();
}
/**
* Commercial bookings on the day's corridor whose operation request was NOT
* accepted by staff (still pending / changes / price-confirm) and are not yet
* linked to a train. These never reached FULLY_EXECUTED, so they never enter the
* batch pool; the window's doc-review end sweeps them to EXPIRED. Government
* bookings are excluded (they don't go through the customer window).
*/
findUnacceptedForRouteDay(
corridorYardIds: string[],
day: string,
): Promise<Booking[]> {
if (corridorYardIds.length === 0) return Promise.resolve([]);
return this.repository
.createQueryBuilder('booking')
.leftJoinAndSelect('booking.company', 'company')
.leftJoin(TrainScheduleBooking, 'sb', 'sb.booking_id = booking.id')
.where('booking.origin_yard_id IN (:...corridorYardIds)', { corridorYardIds })
.andWhere('booking.destination_yard_id IN (:...corridorYardIds)', {
corridorYardIds,
})
.andWhere(
`DATE(booking.scheduled_date AT TIME ZONE 'Africa/Addis_Ababa') = :day`,
{ day },
)
.andWhere('sb.id IS NULL')
.andWhere('booking.is_government = false')
.andWhere(
`booking.status IN (
'OPERATION_REQUESTED',
'OPERATION_REQUEST_PENDING',
'OPERATION_CHANGES_REQUESTED',
'OPERATION_PRICE_PENDING_CONFIRM'
)`,
)
.getMany();
}
/** Every booking that targeted a schedule (any status) — for the batch monitoring board. */
findAllBySchedule(scheduleId: string): Promise<Booking[]> {
return this.repository