This commit is contained in:
Marshal
2026-07-20 10:52:20 +00:00
parent e22b336e8c
commit eb532399d9
7 changed files with 64 additions and 23 deletions

View File

@@ -3444,19 +3444,22 @@ export class BookingBatchService implements OnModuleInit {
/**
* Physical wagons marshalled in the schedule's built train, or null when the
* schedule has no built train (or the consist is still empty) and the legacy
* locomotive-derived capacity must apply. This count is what caps a built
* train's bookings: 50 wagons coupled → 50 wagon slots, no more.
* schedule has NO built train and the legacy locomotive-derived capacity must
* apply. This count is what caps a built train's bookings: 50 wagons coupled
* → 50 wagon slots, no more.
*
* A built train with an EMPTY consist returns 0, NOT null: zero coupled
* wagons means zero capacity. Folding that case into null used to hand an
* un-consisted train the abstract locomotive budget, so an empty train
* advertised its full maxWagons as free space and accepted bookings the
* allocator could never place.
*/
private async builtTrainWagonCount(
schedule: TrainSchedule,
): Promise<number | null> {
const trainId = schedule.trainSet?.train?.id;
if (!trainId) return null;
const count = await this.dataSource
.getRepository(Wagon)
.count({ where: { trainId } });
return count > 0 ? count : null;
return this.dataSource.getRepository(Wagon).count({ where: { trainId } });
}
/**