fix(public-loads): adding vehicle location with populate_list
This commit is contained in:
@@ -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,28 +19,28 @@ 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) => {
|
||||||
const filter = { status : "Published" };
|
try{
|
||||||
const select = [
|
const filter = { status : "Published" };
|
||||||
"shipment_code",
|
const select = [
|
||||||
"categories",
|
"shipment_code",
|
||||||
"truck_type",
|
"categories",
|
||||||
"published_date",
|
"truck_type",
|
||||||
"createdAt",
|
"published_date",
|
||||||
"status",
|
"createdAt",
|
||||||
"weight",
|
"status",
|
||||||
"est_loading_date",
|
"weight",
|
||||||
"est_unloading_date",
|
"est_loading_date",
|
||||||
"origin",
|
"est_unloading_date",
|
||||||
"destination",
|
"origin",
|
||||||
"vehicle.last_location_lat",
|
"destination"
|
||||||
"vehicle.last_location_lng",
|
];
|
||||||
"vehicle.last_location_geo",
|
const { page , elements } = getPagination( req.query );
|
||||||
"vehicle.last_location_time",
|
const retVal = await generic.getList(page , elements, filter, select );
|
||||||
"vehicle.background_tracking"
|
res.send( retVal );
|
||||||
];
|
}catch(error){
|
||||||
const { page , elements } = getPagination( req.query );
|
console.error( error );
|
||||||
const retVal = await generic.getList(page , elements, filter, select );
|
return res.status( 500 ).send({ error: error.message });
|
||||||
res.send( retVal );
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { getList };
|
module.exports = { getList };
|
||||||
|
|||||||
Reference in New Issue
Block a user