mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +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 { DataSource, FindOptionsWhere, In } from 'typeorm';
|
||||||
|
|
||||||
import { BookingsRepository } from '../bookings/bookings.repository';
|
import { BookingsRepository } from '../bookings/bookings.repository';
|
||||||
@@ -165,6 +165,13 @@ export class LastMileService {
|
|||||||
async update(id: string, dto: UpdateLastMileDto): Promise<LastMile> {
|
async update(id: string, dto: UpdateLastMileDto): Promise<LastMile> {
|
||||||
const existing = await this.findById(id);
|
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 dtoAny = dto as any;
|
||||||
const updated = await this.lastMileRepository.update(id, {
|
const updated = await this.lastMileRepository.update(id, {
|
||||||
...(dto.bookingId !== undefined ? { bookingId: dto.bookingId } : {}),
|
...(dto.bookingId !== undefined ? { bookingId: dto.bookingId } : {}),
|
||||||
@@ -261,7 +268,10 @@ export class LastMileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string): Promise<void> {
|
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);
|
await this.lastMileRepository.softDelete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -833,6 +833,7 @@ const LastMilePage = () => {
|
|||||||
const nextStatus = NEXT_STATUS[row.original.status];
|
const nextStatus = NEXT_STATUS[row.original.status];
|
||||||
const canPrint = row.original.status !== "PAYMENT_PENDING";
|
const canPrint = row.original.status !== "PAYMENT_PENDING";
|
||||||
const isPaid = (row.original as any).paid;
|
const isPaid = (row.original as any).paid;
|
||||||
|
const delivered = row.original.status === "DELIVERED";
|
||||||
return (
|
return (
|
||||||
<Group gap={4} justify="flex-end" wrap="nowrap">
|
<Group gap={4} justify="flex-end" wrap="nowrap">
|
||||||
<Menu position="bottom-end" width={200} withinPortal>
|
<Menu position="bottom-end" width={200} withinPortal>
|
||||||
@@ -852,14 +853,14 @@ const LastMilePage = () => {
|
|||||||
<Menu.Divider />
|
<Menu.Divider />
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
leftSection={<Truck size={15} />}
|
leftSection={<Truck size={15} />}
|
||||||
disabled={assigned}
|
disabled={assigned || delivered}
|
||||||
onClick={() => openAssign(row.original.id)}
|
onClick={() => openAssign(row.original.id)}
|
||||||
>
|
>
|
||||||
Assign
|
Assign
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
leftSection={<RefreshCw size={15} />}
|
leftSection={<RefreshCw size={15} />}
|
||||||
disabled={!assigned}
|
disabled={!assigned || delivered}
|
||||||
onClick={() => openAssign(row.original.id)}
|
onClick={() => openAssign(row.original.id)}
|
||||||
>
|
>
|
||||||
Reassign
|
Reassign
|
||||||
@@ -873,6 +874,7 @@ const LastMilePage = () => {
|
|||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
leftSection={<Ruler size={15} />}
|
leftSection={<Ruler size={15} />}
|
||||||
|
disabled={delivered}
|
||||||
onClick={() => openDistance(row.original.id)}
|
onClick={() => openDistance(row.original.id)}
|
||||||
>
|
>
|
||||||
Add distance
|
Add distance
|
||||||
@@ -891,6 +893,7 @@ const LastMilePage = () => {
|
|||||||
<Menu.Item
|
<Menu.Item
|
||||||
leftSection={<Trash size={15} />}
|
leftSection={<Trash size={15} />}
|
||||||
color="red"
|
color="red"
|
||||||
|
disabled={delivered}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (confirm(`Delete last-mile record ${bookingRef(row.original)}?`)) {
|
if (confirm(`Delete last-mile record ${bookingRef(row.original)}?`)) {
|
||||||
deleteMutation.mutate(row.original.id);
|
deleteMutation.mutate(row.original.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user