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";
const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const { GenericHandler } = require( `${ROOT_PATH}/${HANDLERS_PATH}/Generic.handler.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/loads.model.js` );
const categoriesModel = require( `${ROOT_PATH}/${MODELS_PATH}/product-categories.model.js` );
const { getPagination , getPage } = require( '../../../lib/Misc' );
const { GenericHandler } = require( '../../../lib/Handlers/Generic.handler' );
const Model = require( '../../../lib/Models/loads.model.js' );
const categoriesModel = require( '../../../lib/Models/product-categories.model' );
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_lng
// last_location_geo
@@ -14,28 +19,28 @@ const populate_list = ['categories','vehicle'];
const generic = new GenericHandler( Model, null, populate_list );
const getList = async(req, res) => {
const filter = { status : "Published" };
const select = [
"shipment_code",
"categories",
"truck_type",
"published_date",
"createdAt",
"status",
"weight",
"est_loading_date",
"est_unloading_date",
"origin",
"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 retVal = await generic.getList(page , elements, filter, select );
res.send( retVal );
try{
const filter = { status : "Published" };
const select = [
"shipment_code",
"categories",
"truck_type",
"published_date",
"createdAt",
"status",
"weight",
"est_loading_date",
"est_unloading_date",
"origin",
"destination"
];
const { page , elements } = getPagination( req.query );
const retVal = await generic.getList(page , elements, filter, select );
res.send( retVal );
}catch(error){
console.error( error );
return res.status( 500 ).send({ error: error.message });
}
};
module.exports = { getList };