From eb5d8a7411d76c03e9787366eeee85017959d027 Mon Sep 17 00:00:00 2001 From: natib21 Date: Thu, 2 Jul 2026 14:42:04 +0000 Subject: [PATCH] fix --- .../src/modules/last-mile/last-mile.service.ts | 14 ++++++++++++-- .../src/pages/operations/LastMilePage.tsx | 7 +++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/edr-freight-api/src/modules/last-mile/last-mile.service.ts b/apps/edr-freight-api/src/modules/last-mile/last-mile.service.ts index dec6c47b4..54d992bd1 100644 --- a/apps/edr-freight-api/src/modules/last-mile/last-mile.service.ts +++ b/apps/edr-freight-api/src/modules/last-mile/last-mile.service.ts @@ -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 { 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 { - 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); } diff --git a/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx b/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx index 9284c4dae..eb6d88a92 100644 --- a/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx @@ -833,6 +833,7 @@ const LastMilePage = () => { const nextStatus = NEXT_STATUS[row.original.status]; const canPrint = row.original.status !== "PAYMENT_PENDING"; const isPaid = (row.original as any).paid; + const delivered = row.original.status === "DELIVERED"; return ( @@ -852,14 +853,14 @@ const LastMilePage = () => { } - disabled={assigned} + disabled={assigned || delivered} onClick={() => openAssign(row.original.id)} > Assign } - disabled={!assigned} + disabled={!assigned || delivered} onClick={() => openAssign(row.original.id)} > Reassign @@ -873,6 +874,7 @@ const LastMilePage = () => { } + disabled={delivered} onClick={() => openDistance(row.original.id)} > Add distance @@ -891,6 +893,7 @@ const LastMilePage = () => { } color="red" + disabled={delivered} onClick={() => { if (confirm(`Delete last-mile record ${bookingRef(row.original)}?`)) { deleteMutation.mutate(row.original.id);