diff --git a/apps/edr-freight-api/src/modules/train-scheduling/train-capacity.util.ts b/apps/edr-freight-api/src/modules/train-scheduling/train-capacity.util.ts index 463ae7ea8..3e4fab0d3 100644 --- a/apps/edr-freight-api/src/modules/train-scheduling/train-capacity.util.ts +++ b/apps/edr-freight-api/src/modules/train-scheduling/train-capacity.util.ts @@ -253,12 +253,18 @@ export function minLocomotiveLimits( maxTrainLengthMeters: Math.min( ...locomotives.map((l) => num(l.maxTrainLengthMeters, Infinity) || Infinity), ), - // Weakest locomotive's tolerance governs the set, same as its caps. - overageToleranceTons: Math.min(...locomotives.map((l) => num(l.overageToleranceTons))), - overageToleranceMeters: Math.min(...locomotives.map((l) => num(l.overageToleranceMeters))), + // Weakest CONFIGURED tolerance governs the set — a locomotive with no + // tolerance set has no opinion, it does not zero out the others. + overageToleranceTons: minConfigured(locomotives.map((l) => l.overageToleranceTons)), + overageToleranceMeters: minConfigured(locomotives.map((l) => l.overageToleranceMeters)), }; } +function minConfigured(values: Array): number { + const configured = values.filter((v) => v != null).map((v) => num(v)); + return configured.length ? Math.min(...configured) : 0; +} + /** Per-booking train length from wagon count and freight-specific wagon type length. */ export function bookingTrainLengthMeters( freightType: string | null | undefined,