This commit is contained in:
natib21
2026-07-02 14:42:04 +00:00
parent b7da024968
commit eb5d8a7411
2 changed files with 17 additions and 4 deletions

View File

@@ -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);
}