mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
feat(bookings): pending export requests hold wagons
This commit is contained in:
@@ -859,7 +859,9 @@ export class BookingBatchService implements OnModuleInit {
|
||||
const locomotive = trainSetLocomotiveLimits(schedule?.trainSet);
|
||||
if (!schedule || !locomotive) continue;
|
||||
const limits = await this.capacityLimits(locomotive);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims, [
|
||||
booking.id,
|
||||
]);
|
||||
const leg = budget.legOf(booking.originYardId, booking.destinationYardId);
|
||||
if (!leg) continue; // this train's route doesn't carry the booking's leg
|
||||
report.corridorMatched = true;
|
||||
@@ -1012,7 +1014,9 @@ export class BookingBatchService implements OnModuleInit {
|
||||
const locomotive = trainSetLocomotiveLimits(schedule?.trainSet);
|
||||
if (!schedule || !locomotive) continue;
|
||||
const limits = await this.capacityLimits(locomotive);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims, [
|
||||
booking.id,
|
||||
]);
|
||||
const leg = budget.legOf(booking.originYardId, booking.destinationYardId);
|
||||
if (!leg) continue; // this train's route doesn't carry the booking's leg
|
||||
const room = budget.remainingFor(leg);
|
||||
@@ -1128,7 +1132,9 @@ export class BookingBatchService implements OnModuleInit {
|
||||
const locomotive = trainSetLocomotiveLimits(schedule?.trainSet);
|
||||
if (!schedule || !locomotive) continue;
|
||||
const limits = await this.capacityLimits(locomotive);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims, [
|
||||
booking.id,
|
||||
]);
|
||||
const leg = budget.legOf(booking.originYardId, booking.destinationYardId);
|
||||
if (!leg) continue; // this train's route doesn't carry the booking's leg
|
||||
const room = budget.remainingFor(leg);
|
||||
@@ -1281,7 +1287,9 @@ export class BookingBatchService implements OnModuleInit {
|
||||
if (!schedule || !locomotive) return false;
|
||||
const wagonDims = await this.loadWagonDims();
|
||||
const limits = await this.capacityLimits(locomotive);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims, [
|
||||
booking.id,
|
||||
]);
|
||||
const leg = budget.legOf(booking.originYardId, booking.destinationYardId);
|
||||
if (!leg) return false;
|
||||
|
||||
@@ -1382,7 +1390,12 @@ export class BookingBatchService implements OnModuleInit {
|
||||
}
|
||||
const wagonDims = await this.loadWagonDims();
|
||||
const limits = await this.capacityLimits(locomotive);
|
||||
const budget = await this.remainingBudget(schedule, limits, wagonDims);
|
||||
const budget = await this.remainingBudget(
|
||||
schedule,
|
||||
limits,
|
||||
wagonDims,
|
||||
bookings.map((b) => b.id),
|
||||
);
|
||||
const leg = budget.legOf(
|
||||
bookings[0].originYardId,
|
||||
bookings[0].destinationYardId,
|
||||
@@ -4745,6 +4758,7 @@ export class BookingBatchService implements OnModuleInit {
|
||||
schedule: TrainSchedule,
|
||||
limits: TrainLimits,
|
||||
wagonDims: WagonDims,
|
||||
excludeBookingIds?: string[],
|
||||
): Promise<CorridorBudget> {
|
||||
const physicalWagons = await this.builtTrainWagonCount(schedule);
|
||||
if (physicalWagons != null) {
|
||||
@@ -4780,7 +4794,21 @@ export class BookingBatchService implements OnModuleInit {
|
||||
b.status === "PAID" ||
|
||||
!payWindowLapsed(b.paymentDeadline, deadlineCutoff),
|
||||
);
|
||||
for (const b of [...allocated, ...reserved]) {
|
||||
// Export FCFS: a customer's pending operation request HOLDS its wagons from
|
||||
// the moment it is submitted — the request named this exact train
|
||||
// (requestedTrainScheduleId), so its capacity must not be shown to or
|
||||
// booked by anyone else while staff review it. The booking(s) being
|
||||
// evaluated are excluded so a request never blocks its own accept.
|
||||
const pendingHolds = (
|
||||
await this.dataSource.getRepository(Booking).find({
|
||||
where: {
|
||||
requestedTrainScheduleId: schedule.id,
|
||||
status: 'OPERATION_REQUEST_PENDING',
|
||||
} as never,
|
||||
relations: ['bookingContainers'],
|
||||
})
|
||||
).filter((b) => !excludeBookingIds?.includes(b.id));
|
||||
for (const b of [...allocated, ...reserved, ...pendingHolds]) {
|
||||
budget.subtract(
|
||||
this.needFor(b, wagonDims),
|
||||
budget.legForYards(b.originYardId, b.destinationYardId),
|
||||
|
||||
@@ -17,7 +17,7 @@ import { WagonTransferRequestsService } from './wagon-transfer-requests.service'
|
||||
TypeOrmModule.forFeature([
|
||||
Wagon,
|
||||
WagonMovement,
|
||||
WagonStatusLog,
|
||||
WagonStatusLog,
|
||||
WagonTransferRequest,
|
||||
Train,
|
||||
Yard,
|
||||
|
||||
Reference in New Issue
Block a user