mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 14:08:11 +00:00
Merge pull request #834 from Tria-plc/freight_feature/usermanagement
Freight feature/usermanagement
This commit is contained in:
@@ -7131,9 +7131,19 @@ export class TrainSchedulingService {
|
||||
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
await manager.getRepository(TrainSetWagon).delete(trainSetWagonId);
|
||||
// Recount from the slot rows rather than decrementing the cached counter.
|
||||
// A blind `wagonCount - 1` desyncs the moment two removals race or the
|
||||
// in-memory schedule graph is stale, and the counter is what the schedule
|
||||
// capacity math reads.
|
||||
const remaining = await manager.getRepository(TrainSetWagon).find({
|
||||
where: { trainSetId: schedule.trainSetId },
|
||||
select: { id: true, lengthMeters: true },
|
||||
});
|
||||
await manager.getRepository(TrainSet).update(schedule.trainSetId, {
|
||||
wagonCount: Math.max(0, (schedule.trainSet?.wagonCount ?? 0) - 1),
|
||||
totalLengthMeters: Math.max(0, (schedule.trainSet?.totalLengthMeters ?? 0) - (wagon.lengthMeters ?? 0)),
|
||||
wagonCount: remaining.length,
|
||||
totalLengthMeters: roundTons(
|
||||
remaining.reduce((sum, w) => sum + (Number(w.lengthMeters) || 0), 0),
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user