mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 05:58:18 +00:00
fix padding on portal
This commit is contained in:
@@ -20,6 +20,25 @@ export class VehiclesService {
|
||||
private readonly history: FleetHistoryService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* A driver holds one truck at a time — reassignment requires detaching them
|
||||
* from their current truck first.
|
||||
* ponytail: app-level guard only (race window); add a partial unique index on
|
||||
* assigned_driver_id if concurrent fleet edits ever become real.
|
||||
*/
|
||||
private async assertDriverUnassigned(driverId: string, exceptVehicleId?: string): Promise<void> {
|
||||
const holder = await this.vehicleRepo.findOne({
|
||||
where: exceptVehicleId
|
||||
? { assignedDriverId: driverId, id: Not(exceptVehicleId) }
|
||||
: { assignedDriverId: driverId },
|
||||
});
|
||||
if (holder) {
|
||||
throw new ConflictException(
|
||||
`This driver is already assigned to truck ${holder.plateNumber ?? holder.code ?? holder.id} — detach the driver from that truck first`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async create(dto: CreateVehicleDto): Promise<Vehicle> {
|
||||
const existing = await this.vehicleRepo.findOne({
|
||||
where: { plateNumber: dto.plateNumber },
|
||||
@@ -31,6 +50,10 @@ export class VehiclesService {
|
||||
);
|
||||
}
|
||||
|
||||
if (dto.assignedDriverId) {
|
||||
await this.assertDriverUnassigned(dto.assignedDriverId);
|
||||
}
|
||||
|
||||
const registrationNumber = `REG-${dto.vehicleType}-${Date.now()}`;
|
||||
const vehicle = this.vehicleRepo.create({
|
||||
...dto,
|
||||
@@ -121,6 +144,10 @@ export class VehiclesService {
|
||||
}
|
||||
}
|
||||
|
||||
if (dto.assignedDriverId && dto.assignedDriverId !== vehicle.assignedDriverId) {
|
||||
await this.assertDriverUnassigned(dto.assignedDriverId, id);
|
||||
}
|
||||
|
||||
const prev = {
|
||||
assignedDriverId: vehicle.assignedDriverId,
|
||||
assignedDriverName: vehicle.assignedDriverName,
|
||||
|
||||
Reference in New Issue
Block a user