update window range

This commit is contained in:
Marshal
2026-06-13 07:59:48 +00:00
parent d3a479c142
commit b2f13c95c5
5 changed files with 426 additions and 16 deletions

View File

@@ -19,9 +19,7 @@ import { TrainScheduleBookingsRepository } from '../train-schedules/train-schedu
import { TrainSchedulingGlobalRules } from './entities/train-scheduling-global-rules.entity';
import { BookingNotifierService } from './booking-notifier.service';
import { TrainSchedulingService } from './train-scheduling.service';
import {
groupByBatchWindow,
} from './batch-window.util';
import { groupBookingsIntoBoardWindows } from './batch-window.util';
import {
BATCH_CRON,
BATCH_TIMEZONE,
@@ -82,6 +80,10 @@ export interface BatchBoardBookingDetail extends BatchBoardBooking {
export interface BatchWindowGroup {
key: string;
label: string;
/** EAT calendar day as ISO `YYYY-MM-DD` (empty for the pending-contract bucket). */
date: string;
/** Human label for the day, e.g. `Thu, 05 Jun` (empty for pending-contract). */
dateLabel: string;
start: string;
end: string;
counts: {
@@ -401,11 +403,15 @@ export class BookingBatchService implements OnModuleInit {
const loco = s.trainSet?.locomotive ?? null;
const referenceDate = s.scheduledDepartureDate ?? new Date();
const windowBuckets = groupByBatchWindow(
// Display windows span the whole booking window: from when it opened
// (schedule creation) through the scheduled departure, in 3-hour EAT slots.
const openDate = s.createdAt ?? s.scheduledDepartureDate ?? new Date();
const departureDate = s.scheduledDepartureDate ?? new Date();
const windowBuckets = groupBookingsIntoBoardWindows(
items,
(item) => (item.fullyExecutedAt ? new Date(item.fullyExecutedAt) : null),
referenceDate,
openDate,
departureDate,
);
const emptyCounts = () => ({
@@ -437,6 +443,8 @@ export class BookingBatchService implements OnModuleInit {
windows.push({
key: w.key,
label: w.label,
date: w.date,
dateLabel: w.dateLabel,
start: w.start.toISOString(),
end: w.end.toISOString(),
counts: countFor(bucket.items),
@@ -477,6 +485,8 @@ export class BookingBatchService implements OnModuleInit {
pendingContract: {
key: 'pending-contract',
label: 'Pending contract',
date: '',
dateLabel: '',
start: '',
end: '',
counts: countFor(pendingBookings),