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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<Group gap={4} justify="flex-end" wrap="nowrap">
|
||||
<Menu position="bottom-end" width={200} withinPortal>
|
||||
@@ -852,14 +853,14 @@ const LastMilePage = () => {
|
||||
<Menu.Divider />
|
||||
<Menu.Item
|
||||
leftSection={<Truck size={15} />}
|
||||
disabled={assigned}
|
||||
disabled={assigned || delivered}
|
||||
onClick={() => openAssign(row.original.id)}
|
||||
>
|
||||
Assign
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
leftSection={<RefreshCw size={15} />}
|
||||
disabled={!assigned}
|
||||
disabled={!assigned || delivered}
|
||||
onClick={() => openAssign(row.original.id)}
|
||||
>
|
||||
Reassign
|
||||
@@ -873,6 +874,7 @@ const LastMilePage = () => {
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
leftSection={<Ruler size={15} />}
|
||||
disabled={delivered}
|
||||
onClick={() => openDistance(row.original.id)}
|
||||
>
|
||||
Add distance
|
||||
@@ -891,6 +893,7 @@ const LastMilePage = () => {
|
||||
<Menu.Item
|
||||
leftSection={<Trash size={15} />}
|
||||
color="red"
|
||||
disabled={delivered}
|
||||
onClick={() => {
|
||||
if (confirm(`Delete last-mile record ${bookingRef(row.original)}?`)) {
|
||||
deleteMutation.mutate(row.original.id);
|
||||
|
||||
Reference in New Issue
Block a user