mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 15:48:11 +00:00
feat(train-scheduling): load returned empties onto an export train
Empties had no way onto a departure: the return record could name a train but nothing seated it on a wagon. Export schedules now expose a loading action that packs selected returns onto free wagons at one 40ft or two 20ft each, enforced both in the picker and in the API (existing empties on the schedule count against their wagon). Adds container_size, train_schedule_id and wagon_sequence_no to freight.empty_container_returns.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
/**
|
||||
* A wagon carries ONE 40ft OR TWO 20ft empties — never a mix, never three.
|
||||
* Throws on the first wagon that breaks the rule.
|
||||
*/
|
||||
export function assertWagonLoad(sizesByWagon: Map<number, string[]>): void {
|
||||
for (const [wagon, sizes] of sizesByWagon) {
|
||||
const has40 = sizes.some((size) => size === '40');
|
||||
if ((has40 && sizes.length > 1) || sizes.length > 2) {
|
||||
throw new BadRequestException(
|
||||
`Wagon ${wagon} takes one 40ft or two 20ft containers — got ${sizes.join('ft + ')}ft`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user