fix(public-loads): adding vehicle location with populate_list

This commit is contained in:
Josepablo C
2024-10-03 21:44:50 -06:00
parent ddca2f24b5
commit 46de083c41

View File

@@ -1,11 +1,16 @@
"use strict"; "use strict";
const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env; const { getPagination , getPage } = require( '../../../lib/Misc' );
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` ); const { GenericHandler } = require( '../../../lib/Handlers/Generic.handler' );
const { GenericHandler } = require( `${ROOT_PATH}/${HANDLERS_PATH}/Generic.handler.js` ); const Model = require( '../../../lib/Models/loads.model.js' );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/loads.model.js` ); const categoriesModel = require( '../../../lib/Models/product-categories.model' );
const categoriesModel = require( `${ROOT_PATH}/${MODELS_PATH}/product-categories.model.js` );
const populate_list = ['categories','vehicle']; const populate_list = [
'categories',
{
path:'vehicle',
select:"last_location_lat last_location_lng last_location_geo last_location_time background_tracking"
}
];
// last_location_lat // last_location_lat
// last_location_lng // last_location_lng
// last_location_geo // last_location_geo
@@ -14,6 +19,7 @@ const populate_list = ['categories','vehicle'];
const generic = new GenericHandler( Model, null, populate_list ); const generic = new GenericHandler( Model, null, populate_list );
const getList = async(req, res) => { const getList = async(req, res) => {
try{
const filter = { status : "Published" }; const filter = { status : "Published" };
const select = [ const select = [
"shipment_code", "shipment_code",
@@ -26,16 +32,15 @@ const getList = async(req, res) => {
"est_loading_date", "est_loading_date",
"est_unloading_date", "est_unloading_date",
"origin", "origin",
"destination", "destination"
"vehicle.last_location_lat",
"vehicle.last_location_lng",
"vehicle.last_location_geo",
"vehicle.last_location_time",
"vehicle.background_tracking"
]; ];
const { page , elements } = getPagination( req.query ); const { page , elements } = getPagination( req.query );
const retVal = await generic.getList(page , elements, filter, select ); const retVal = await generic.getList(page , elements, filter, select );
res.send( retVal ); res.send( retVal );
}catch(error){
console.error( error );
return res.status( 500 ).send({ error: error.message });
}
}; };
module.exports = { getList }; module.exports = { getList };