mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 02:58:11 +00:00
feat(freight): offer built-train wagons per boarding yard on multi-yard consists
This commit is contained in:
@@ -1221,13 +1221,21 @@ export class BookingBatchService implements OnModuleInit {
|
||||
const ledger = new WagonStockLedger(
|
||||
stock.remainingByTypeId,
|
||||
Math.max(1, budget.stops.length - 1),
|
||||
stock.byYardId,
|
||||
budget.stops,
|
||||
);
|
||||
// On a multi-yard consist the pool that matters is the one standing at
|
||||
// the booking's own boarding yard — a type carried only in Mojo must not
|
||||
// be advertised to a customer boarding at Dire.
|
||||
const carriedAtBoardYard = (wagonTypeId: string): number => {
|
||||
const boardYardId = stock.byYardId ? budget.stops[leg.fromEdge] : null;
|
||||
if (boardYardId) return stock.byYardId?.get(boardYardId)?.get(wagonTypeId) ?? 0;
|
||||
return stock.remainingByTypeId.get(wagonTypeId) ?? 0;
|
||||
};
|
||||
const byWagonType = allowed
|
||||
.filter(
|
||||
({ wagonTypeId }) =>
|
||||
stock.mode !== 'TRAIN' ||
|
||||
!wagonTypeId ||
|
||||
(stock.remainingByTypeId.get(wagonTypeId) ?? 0) > 0,
|
||||
stock.mode !== 'TRAIN' || !wagonTypeId || carriedAtBoardYard(wagonTypeId) > 0,
|
||||
)
|
||||
.map(({ wagonTypeId, dims }) => {
|
||||
const type = wagonTypeId ? typeById.get(wagonTypeId) : undefined;
|
||||
@@ -4783,6 +4791,8 @@ export class BookingBatchService implements OnModuleInit {
|
||||
return new WagonStockLedger(
|
||||
stock.remainingByTypeId,
|
||||
Math.max(1, budget.stops.length - 1),
|
||||
stock.byYardId,
|
||||
budget.stops,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user