diff --git a/v1/src/apps/private/loads/services.js b/v1/src/apps/private/loads/services.js index 5a639c4..553ebb8 100644 --- a/v1/src/apps/private/loads/services.js +++ b/v1/src/apps/private/loads/services.js @@ -23,7 +23,9 @@ const vehicle_projection = [ 'circulation_serial_number', 'trailer_plate_1', 'trailer_plate_2', + 'notes', 'city', + 'available_in' ]; const user_projection = ['first_name','last_name','middle_name']; const populate_list = [ @@ -33,7 +35,7 @@ const populate_list = [ 'origin_warehouse', 'destination_warehouse', {path:'carrier',select: carrier_projection }, - {path:'vehicle',select: vehicle_projection }, + {path:'vehicle',select: vehicle_projection, populate : { path : 'categories' } }, {path:'driver',select: user_projection }, {path:'bidder',select: user_projection }, ]; @@ -164,8 +166,6 @@ async function findLoads( query ){ filter = null; } - console.log( andFilterList ); - const { total , limit, skip, data } = await generic.getList( page , elements, filter, null, $sort ); const load_list = data; diff --git a/v1/src/config/apiConfig.json b/v1/src/config/apiConfig.json index eed74a4..c8b4091 100644 --- a/v1/src/config/apiConfig.json +++ b/v1/src/config/apiConfig.json @@ -16,7 +16,7 @@ } }, "version" : { - "version" : "1.5.3", + "version" : "1.5.4", "name": "ETA Beta", "date":"21/07/2025" }, diff --git a/v1/src/lib/Handlers/Events/Proposals/index.js b/v1/src/lib/Handlers/Events/Proposals/index.js index 9c3b38e..01902dc 100644 --- a/v1/src/lib/Handlers/Events/Proposals/index.js +++ b/v1/src/lib/Handlers/Events/Proposals/index.js @@ -101,12 +101,28 @@ async function onProposalVehicleChanged( userId, proposalId ){ const proposal = await proposalsModel.findById( proposalId ); const vehicle = await vehiclesModel.findById( proposal.vehicle ); + const vehicle_list = await vehiclesModel.find({ + active_load: proposal.load + }); + /// Update Load: /// Add driver and vehicle await loadsModel.findByIdAndUpdate( proposal.load, { driver : vehicle.driver, vehicle : proposal.vehicle } ); + + /// Update vehicles related to this load. Ideally, just one. + for( const item of vehicle_list ){ + await vehiclesModel.findByIdAndUpdate( + item.id, + { + active_load: null, + load_shipper: null, + status: "Free" + } + ); + } } module.exports = { onProposalCreate, onProposalRejected, onProposalAccepted, onProposalVehicleChanged };