mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';
|
||||
import { DataSource, FindOptionsWhere, In } from 'typeorm';
|
||||
|
||||
import { BookingsRepository } from '../bookings/bookings.repository';
|
||||
@@ -165,6 +165,13 @@ export class LastMileService {
|
||||
async update(id: string, dto: UpdateLastMileDto): Promise<LastMile> {
|
||||
const existing = await this.findById(id);
|
||||
|
||||
if (
|
||||
existing.status === 'DELIVERED' &&
|
||||
(dto.vehicleId !== undefined || dto.exactKm !== undefined)
|
||||
) {
|
||||
throw new BadRequestException('Delivered records cannot be reassigned or have distance changed');
|
||||
}
|
||||
|
||||
const dtoAny = dto as any;
|
||||
const updated = await this.lastMileRepository.update(id, {
|
||||
...(dto.bookingId !== undefined ? { bookingId: dto.bookingId } : {}),
|
||||
@@ -261,7 +268,10 @@ export class LastMileService {
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<void> {
|
||||
await this.findById(id);
|
||||
const existing = await this.findById(id);
|
||||
if (existing.status === 'DELIVERED') {
|
||||
throw new BadRequestException('Delivered records cannot be deleted');
|
||||
}
|
||||
await this.lastMileRepository.softDelete(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user