From 5b1d2e2984b8aa6f380b820ae7c7b03736328cc6 Mon Sep 17 00:00:00 2001 From: natib21 Date: Wed, 24 Jun 2026 13:14:33 +0000 Subject: [PATCH 1/3] fix --- .../src/modules/last-mile/last-mile.module.ts | 11 +++- .../modules/last-mile/last-mile.service.ts | 53 ++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/apps/edr-freight-api/src/modules/last-mile/last-mile.module.ts b/apps/edr-freight-api/src/modules/last-mile/last-mile.module.ts index fa654f6ec..32c2de721 100644 --- a/apps/edr-freight-api/src/modules/last-mile/last-mile.module.ts +++ b/apps/edr-freight-api/src/modules/last-mile/last-mile.module.ts @@ -2,13 +2,22 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { BookingsModule } from '../bookings/bookings.module'; +import { DriversModule } from '../drivers/drivers.module'; +import { NotificationsModule } from '../notifications/notifications.module'; +import { VehiclesModule } from '../vehicles/vehicles.module'; import { LastMile } from './entities/last-mile.entity'; import { LastMileController } from './last-mile.controller'; import { LastMileRepository } from './last-mile.repository'; import { LastMileService } from './last-mile.service'; @Module({ - imports: [TypeOrmModule.forFeature([LastMile]), BookingsModule], + imports: [ + TypeOrmModule.forFeature([LastMile]), + BookingsModule, + VehiclesModule, + DriversModule, + NotificationsModule, + ], controllers: [LastMileController], providers: [LastMileRepository, LastMileService], exports: [LastMileRepository, LastMileService], 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 d25729324..1dc0ce48d 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,7 +1,10 @@ -import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'; +import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common'; import { FindOptionsWhere } from 'typeorm'; import { BookingsRepository } from '../bookings/bookings.repository'; +import { DriversService } from '../drivers/drivers.service'; +import { NotificationsService } from '../notifications/notifications.service'; +import { VehiclesService } from '../vehicles/vehicles.service'; import { CreateLastMileDto } from './dto/create-last-mile.dto'; import { UpdateLastMileDto } from './dto/update-last-mile.dto'; import { LastMile, LastMileStatus } from './entities/last-mile.entity'; @@ -26,9 +29,14 @@ const SORTABLE_FIELDS: (keyof LastMile)[] = [ @Injectable() export class LastMileService { + private readonly logger = new Logger(LastMileService.name); + constructor( private readonly lastMileRepository: LastMileRepository, private readonly bookingsRepository: BookingsRepository, + private readonly vehiclesService: VehiclesService, + private readonly driversService: DriversService, + private readonly notificationsService: NotificationsService, ) {} async acceptBooking(bookingReference: string): Promise { @@ -116,7 +124,7 @@ export class LastMileService { } async update(id: string, dto: UpdateLastMileDto): Promise { - await this.findById(id); + const existing = await this.findById(id); const updated = await this.lastMileRepository.update(id, { ...(dto.bookingId !== undefined ? { bookingId: dto.bookingId } : {}), @@ -132,9 +140,50 @@ export class LastMileService { throw new NotFoundException(`Last-mile record ${id} not found`); } + // Notify assigned driver on every explicit vehicle assignment or reassignment + if (dto.vehicleId) { + void this.notifyDriverAssignment(dto.vehicleId, existing); + } + return updated; } + private async notifyDriverAssignment(vehicleId: string, record: LastMile): Promise { + try { + const vehicle = await this.vehiclesService.findById(vehicleId); + if (!vehicle.assignedDriverId) { + this.logger.warn(`Vehicle ${vehicleId} has no assigned driver — skipping SMS`); + return; + } + + const driver = await this.driversService.findById(vehicle.assignedDriverId); + if (!driver.phoneNumber) { + this.logger.warn(`Driver ${vehicle.assignedDriverId} has no phone number — skipping SMS`); + return; + } + + type BookingWithYards = { + reference?: string; + lastMileDeliveryAddress?: string | null; + destinationYard?: { label?: string } | null; + }; + const booking = (record as LastMile & { booking?: BookingWithYards }).booking; + + await this.notificationsService.notifyDriverVehicleAssignment({ + driverPhone: driver.phoneNumber, + driverName: `${driver.firstName ?? ''} ${driver.lastName ?? ''}`.trim(), + vehiclePlateNumber: vehicle.plateNumber ?? vehicleId, + bookingReference: booking?.reference ?? record.bookingId, + pickupAddress: booking?.destinationYard?.label, + destinationYard: booking?.lastMileDeliveryAddress, + }); + + this.logger.log(`SMS sent to driver ${driver.phoneNumber} for vehicle ${vehicleId} assignment`); + } catch (err) { + this.logger.error(`Failed to notify driver for vehicle ${vehicleId}: ${String(err)}`); + } + } + async remove(id: string): Promise { await this.findById(id); await this.lastMileRepository.softDelete(id); From ae947955aa85fb1eccd8aa9df46547502825d4bd Mon Sep 17 00:00:00 2001 From: natib21 Date: Wed, 24 Jun 2026 13:51:19 +0000 Subject: [PATCH 2/3] fix issue --- apps/edr-freight-api/src/modules/payment/payment.module.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/edr-freight-api/src/modules/payment/payment.module.ts b/apps/edr-freight-api/src/modules/payment/payment.module.ts index 02adc1885..945dea459 100644 --- a/apps/edr-freight-api/src/modules/payment/payment.module.ts +++ b/apps/edr-freight-api/src/modules/payment/payment.module.ts @@ -57,6 +57,7 @@ function rabbitMQImport(): DynamicModule[] { HttpModule.register({ timeout: 10_000 }), ConfigModule, DropdownSettingsModule, + forwardRef(() => FirstMileModule), forwardRef(() => TrainSchedulingModule), TypeOrmModule.forFeature([PaymentWebhookEventEntity, PaymentRefundEntity]), ...rabbitMQImport(), From 6239358bf298b04e4642b1807b0246c1a4703001 Mon Sep 17 00:00:00 2001 From: yaschalew Date: Wed, 24 Jun 2026 16:56:02 +0300 Subject: [PATCH 3/3] fix url --- apps/edr-freight-web/backoffice/src/constants/apiConfig.ts | 4 ++-- apps/edr-freight-web/portal/src/constants/apiConfig.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts b/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts index a7c8670cf..030b051a1 100644 --- a/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts +++ b/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts @@ -1,3 +1,3 @@ -// export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; +export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; -export const API_BASE_URL = 'http://localhost:3001'; +// export const API_BASE_URL = 'http://localhost:3001'; diff --git a/apps/edr-freight-web/portal/src/constants/apiConfig.ts b/apps/edr-freight-web/portal/src/constants/apiConfig.ts index fc9f57a58..dce8aad63 100644 --- a/apps/edr-freight-web/portal/src/constants/apiConfig.ts +++ b/apps/edr-freight-web/portal/src/constants/apiConfig.ts @@ -1,3 +1,3 @@ -// export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; -export const API_BASE_URL = 'http://localhost:3001'; +export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; +// export const API_BASE_URL = 'http://localhost:3001';