diff --git a/apps/edr-freight-api/src/modules/first-mile/first-mile.controller.ts b/apps/edr-freight-api/src/modules/first-mile/first-mile.controller.ts index 161604e81..78c3d43ff 100644 --- a/apps/edr-freight-api/src/modules/first-mile/first-mile.controller.ts +++ b/apps/edr-freight-api/src/modules/first-mile/first-mile.controller.ts @@ -59,7 +59,7 @@ export class FirstMileController { @TrainSchedulingManage() @ApiOperation({ summary: 'Accept a paid booking and create a first-mile leg' }) acceptBooking(@Param('reference') reference: string) { - return this.firstMileService.acceptBooking(reference); + return this.firstMileService.acceptBookingByReference(reference); } @Post() diff --git a/apps/edr-freight-api/src/modules/first-mile/first-mile.service.ts b/apps/edr-freight-api/src/modules/first-mile/first-mile.service.ts index cb35f9a89..a00e54fff 100644 --- a/apps/edr-freight-api/src/modules/first-mile/first-mile.service.ts +++ b/apps/edr-freight-api/src/modules/first-mile/first-mile.service.ts @@ -44,8 +44,8 @@ export class FirstMileService { * paid before any first-mile work proceeds. Throws if the reference is * unknown or the booking has not reached PAID status. */ - async acceptBooking(bookingReference: string): Promise { - const booking = await this.bookingsRepository.findByReference(bookingReference); + async acceptBooking(bookingId: string): Promise { + const booking = await this.bookingsRepository.findById(bookingId); if (!booking) { return null; @@ -61,6 +61,22 @@ export class FirstMileService { }); } + async acceptBookingByReference(bookingReference: string): Promise { + const booking = await this.bookingsRepository.findByReference(bookingReference); + + if (!booking) { + return null; + } + + if (booking.paymentStatus !== 'PAID') { + return null; + } + + return this.create({ + bookingId: booking.id, + advancedPayment: 0, + }); + } async findAll(filter: FirstMileListFilter = {}): Promise<{ data: FirstMile[]; meta: { total: number; page: number; pageSize: number; totalPages: number }; diff --git a/apps/edr-freight-api/src/modules/last-mile/last-mile.controller.ts b/apps/edr-freight-api/src/modules/last-mile/last-mile.controller.ts index ea1e29a3d..e8abf52c6 100644 --- a/apps/edr-freight-api/src/modules/last-mile/last-mile.controller.ts +++ b/apps/edr-freight-api/src/modules/last-mile/last-mile.controller.ts @@ -59,7 +59,7 @@ export class LastMileController { @TrainSchedulingManage() @ApiOperation({ summary: 'Accept a paid booking and create a last-mile leg' }) acceptBooking(@Param('reference') reference: string) { - return this.lastMileService.acceptBooking(reference); + return this.lastMileService.acceptBookingByReference(reference); } @Post() 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 1dc0ce48d..b764d3428 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 @@ -54,7 +54,26 @@ export class LastMileService { return this.create({ bookingId: booking.id, - advancedPayment: booking.totalAmount, + advancedPayment: 0, + }); + } + + async acceptBookingByReference(bookingReference: string): Promise { + const booking = await this.bookingsRepository.findByReference(bookingReference); + + if (!booking) { + throw new NotFoundException(`Booking ${bookingReference} not found`); + } + + if (booking.paymentStatus !== 'PAID') { + throw new BadRequestException( + `Booking ${bookingReference} is not paid (payment status: ${booking.paymentStatus})`, + ); + } + + return this.create({ + bookingId: booking.id, + advancedPayment: 0, }); } diff --git a/apps/edr-freight-web/backoffice/src/App.tsx b/apps/edr-freight-web/backoffice/src/App.tsx index ba465b962..7bdb7e18b 100644 --- a/apps/edr-freight-web/backoffice/src/App.tsx +++ b/apps/edr-freight-web/backoffice/src/App.tsx @@ -72,6 +72,7 @@ import WarehouseInventoryPage from "./pages/warehouses/WarehouseInventoryPage"; import WarehouseInvoicesPage from "./pages/warehouses/WarehouseInvoicesPage"; import WarehouseListPage from "./pages/warehouses/WarehouseListPage"; import WarehouseRulesPage from "./pages/warehouses/WarehouseRulesPage"; +import { HealthCheck } from "./features/health/HealthCheck"; const buildSidebarSections = (demoItems: SidebarItem[]): SidebarSection[] => [ { @@ -353,6 +354,7 @@ const App = () => { return ( } /> + } /> } /> } /> }> @@ -388,138 +390,138 @@ const App = () => { } /> } /> - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> + + + + } + /> } diff --git a/apps/edr-freight-web/backoffice/src/features/health/HealthCheck.tsx b/apps/edr-freight-web/backoffice/src/features/health/HealthCheck.tsx new file mode 100644 index 000000000..96d51298b --- /dev/null +++ b/apps/edr-freight-web/backoffice/src/features/health/HealthCheck.tsx @@ -0,0 +1,11 @@ +export const HealthCheck = () => { + const url1 = import.meta.env.VITE_API_URL?? "undefined"; + const url2 = import.meta.env.VITE_BASE_API_URL?? "undefined"; + const url3 = import.meta.env.VITE_USER_MANAGEMENT_BASE?? "undefined"; + + return
+

-----------{url1}

+

-----------{url2}

+

-----------{url3}

+
+} \ No newline at end of file