From e2bd4b8343f2b52822c328fc652707d9f585316b Mon Sep 17 00:00:00 2001 From: Josepablo C Date: Tue, 22 Jul 2025 23:47:06 -0600 Subject: [PATCH] fix(vehicles::events): on driver changed modify loads that are applicable --- v1/src/config/apiConfig.json | 2 +- v1/src/lib/Handlers/Events/Vehicles/index.js | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/v1/src/config/apiConfig.json b/v1/src/config/apiConfig.json index 92c2c18..a9a87f7 100644 --- a/v1/src/config/apiConfig.json +++ b/v1/src/config/apiConfig.json @@ -16,7 +16,7 @@ } }, "version" : { - "version" : "1.5.8", + "version" : "1.5.9", "name": "ETA Beta", "date":"22/07/2025" }, diff --git a/v1/src/lib/Handlers/Events/Vehicles/index.js b/v1/src/lib/Handlers/Events/Vehicles/index.js index aebafb9..46119cf 100644 --- a/v1/src/lib/Handlers/Events/Vehicles/index.js +++ b/v1/src/lib/Handlers/Events/Vehicles/index.js @@ -50,16 +50,18 @@ async function onVehicleDriverChanged( userId, vehicleId ){ for( const proposal of proposal_list ){ if( proposal.is_accepted === true ){ const load = await loadsModel.findById( proposal.load ); - const origin_warehouse = await branchesModel.findById( load.origin_warehouse ); - const destination_warehouse = await branchesModel.findById( load.destination_warehouse ); - const carrier = await companiesModel.findById( load.carrier ) || {}; - const product = await productsModel.findById( load.product ) || {}; + if( load ){ + const origin_warehouse = await branchesModel.findById( load.origin_warehouse ); + const destination_warehouse = await branchesModel.findById( load.destination_warehouse ); + const carrier = await companiesModel.findById( load.carrier ) || {}; + const product = await productsModel.findById( load.product ) || {}; - if( origin_warehouse ){ - await onDriverChanged.sendWarehouseNotification( origin_warehouse, load, carrier, product, vehicle, driver ); - } - if( destination_warehouse ){ - await onDriverChanged.sendWarehouseNotification( destination_warehouse, load, carrier, product, vehicle, driver ); + if( origin_warehouse ){ + await onDriverChanged.sendWarehouseNotification( origin_warehouse, load, carrier, product, vehicle, driver ); + } + if( destination_warehouse ){ + await onDriverChanged.sendWarehouseNotification( destination_warehouse, load, carrier, product, vehicle, driver ); + } } } }