mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 01:48:12 +00:00
add overnight desk handling and effective window configuration for train schedules
This commit is contained in:
@@ -9,7 +9,7 @@ import { TrainSchedule } from '../train-schedules/entities/train-schedule.entity
|
||||
import { TrainSchedulesRepository } from '../train-schedules/train-schedules.repository';
|
||||
import { NotificationsService } from '../notifications/notifications.service';
|
||||
import { BookingBatchService } from './booking-batch.service';
|
||||
import { TrainSchedulingService } from './train-scheduling.service';
|
||||
import { TrainSchedulingService, effectiveWindowConfig } from './train-scheduling.service';
|
||||
import { BATCH_TIMEZONE } from './booking-batch.constants';
|
||||
import { eatDay, nextCycleOpensAt, type OfficeHours } from './batch-window.util';
|
||||
import { type BookingWindowConfig } from './booking-window.config';
|
||||
@@ -54,7 +54,7 @@ export class BookingWindowService implements OnModuleInit {
|
||||
this.ticking = true;
|
||||
try {
|
||||
const now = new Date();
|
||||
const cfg = await this.trainSchedulingService.getWindowConfig();
|
||||
const liveCfg = await this.trainSchedulingService.getWindowConfig();
|
||||
|
||||
const active = (
|
||||
await this.trainSchedulesRepository.findAll({
|
||||
@@ -71,7 +71,15 @@ export class BookingWindowService implements OnModuleInit {
|
||||
|
||||
for (const schedule of active) {
|
||||
try {
|
||||
await this.advanceSchedule(schedule, cfg, now);
|
||||
// Each train runs under its OWN frozen rule snapshot, not the live global
|
||||
// config — a later global-rules edit must not retro-change the window an
|
||||
// existing train already advertised, and the reopen cycles must match the
|
||||
// board (which is drawn from the same snapshot).
|
||||
await this.advanceSchedule(
|
||||
schedule,
|
||||
effectiveWindowConfig(schedule, liveCfg),
|
||||
now,
|
||||
);
|
||||
} catch (err) {
|
||||
this.logger.error(
|
||||
`Window transition failed for schedule ${schedule.id}: ${(err as Error).message}`,
|
||||
@@ -102,7 +110,7 @@ export class BookingWindowService implements OnModuleInit {
|
||||
return schedule;
|
||||
}
|
||||
const now = new Date();
|
||||
const cfg = await this.trainSchedulingService.getWindowConfig();
|
||||
const liveCfg = await this.trainSchedulingService.getWindowConfig();
|
||||
// Stamp the whole route-day group so one staff action releases every train
|
||||
// sharing this booking day's pool.
|
||||
const group = (
|
||||
@@ -123,7 +131,7 @@ export class BookingWindowService implements OnModuleInit {
|
||||
.getRepository(TrainSchedule)
|
||||
.update(s.id, { docReviewCompletedAt: now });
|
||||
s.docReviewCompletedAt = now;
|
||||
await this.advanceSchedule(s, cfg, now);
|
||||
await this.advanceSchedule(s, effectiveWindowConfig(s, liveCfg), now);
|
||||
}
|
||||
const fresh = await this.trainSchedulesRepository.findById(scheduleId);
|
||||
return fresh ?? schedule;
|
||||
|
||||
Reference in New Issue
Block a user