mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 19:58:11 +00:00
mile
This commit is contained in:
@@ -365,20 +365,28 @@ export class LastMileService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Free every vehicle held by this record (direct assignment + container
|
||||
* allocations), unless still in use by another active trip.
|
||||
* Free every vehicle held by this record — junction assignments, the legacy
|
||||
* direct vehicle, and container allocations — unless still used by another
|
||||
* active trip.
|
||||
*/
|
||||
private async releaseVehicles(record: LastMile): Promise<void> {
|
||||
const recordAllocations = await this.dataSource.manager.find(
|
||||
LastMileContainerAllocation,
|
||||
{ where: { lastMileId: record.id } },
|
||||
);
|
||||
const vehicleIds = recordAllocations
|
||||
.map((a) => a.vehicleId)
|
||||
.filter((id): id is string => Boolean(id));
|
||||
if (record.vehicleId) {
|
||||
vehicleIds.push(record.vehicleId);
|
||||
}
|
||||
const [assignments, recordAllocations] = await Promise.all([
|
||||
this.dataSource.manager.find(LastMileVehicleAssignment, {
|
||||
where: { lastMileId: record.id },
|
||||
}),
|
||||
this.dataSource.manager.find(LastMileContainerAllocation, {
|
||||
where: { lastMileId: record.id },
|
||||
}),
|
||||
]);
|
||||
const vehicleIds = [
|
||||
...new Set(
|
||||
[
|
||||
...assignments.map((a) => a.vehicleId),
|
||||
...recordAllocations.map((a) => a.vehicleId),
|
||||
record.vehicleId ?? null,
|
||||
].filter((id): id is string => Boolean(id)),
|
||||
),
|
||||
];
|
||||
await this.vehiclesService.releaseIfUnused(vehicleIds);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user