mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 23:28:11 +00:00
fix issues
This commit is contained in:
@@ -3174,6 +3174,53 @@ export class TrainSchedulingService {
|
||||
return days.includes(day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforce the config-driven booking window at booking-create time.
|
||||
*
|
||||
* A booking is only allowed when the route has an OPEN departure the customer
|
||||
* can join for the requested day — which, because the window engine keeps
|
||||
* `bookingWindowStatus === 'OPEN'` in lockstep with the live window, means:
|
||||
* - IMPORT: the day's window is currently open (opens at `windowOpenHour` EAT,
|
||||
* `importWindowLeadDays` before departure, for `windowDurationHours`).
|
||||
* - EXPORT: now is within `exportBookingLeadHours` before that departure (FCFS).
|
||||
*
|
||||
* `getBookableScheduleEntities` filters on `bookingWindowStatus === 'OPEN'`, so
|
||||
* both gates are satisfied by checking that route for open departures. When a
|
||||
* specific day is requested, require an open departure on that EAT day; when no
|
||||
* day is given, require at least one open departure on the route at all.
|
||||
* Throws `BadRequestException` when the window is closed. No-ops when the route
|
||||
* yards are unknown (nothing to gate against).
|
||||
*/
|
||||
async assertBookingWindowOpen(input: {
|
||||
originYardId?: string | null;
|
||||
destinationYardId?: string | null;
|
||||
scheduledDate?: Date | string | null;
|
||||
direction?: string | null;
|
||||
}): Promise<void> {
|
||||
const { originYardId, destinationYardId } = input;
|
||||
if (!originYardId || !destinationYardId) return;
|
||||
|
||||
const { days } = await this.getAvailableDays(originYardId, destinationYardId);
|
||||
if (days.length === 0) {
|
||||
throw new BadRequestException(
|
||||
input.direction === 'EXPORT'
|
||||
? 'The export booking window for this route is not open yet'
|
||||
: 'The import booking window for this route is closed right now',
|
||||
);
|
||||
}
|
||||
|
||||
if (input.scheduledDate) {
|
||||
const day = eatDay(new Date(input.scheduledDate));
|
||||
if (!days.includes(day)) {
|
||||
throw new BadRequestException(
|
||||
input.direction === 'EXPORT'
|
||||
? 'No departure is within the export booking window on the selected day'
|
||||
: 'The import booking window is not open for the selected day',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async mapScheduleDetail(
|
||||
schedule: import('../train-schedules/entities/train-schedule.entity').TrainSchedule,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user