fix: Fix tracking issues and remove active_load from user model
This commit is contained in:
@@ -22,6 +22,7 @@ const getById = async(req, res) => {
|
|||||||
const elementId = req.params.id;
|
const elementId = req.params.id;
|
||||||
const select = [
|
const select = [
|
||||||
"categories",
|
"categories",
|
||||||
|
"shipment_code",
|
||||||
"truck_type",
|
"truck_type",
|
||||||
"published_date",
|
"published_date",
|
||||||
"createdAt",
|
"createdAt",
|
||||||
@@ -31,11 +32,13 @@ const getById = async(req, res) => {
|
|||||||
"est_loading_date",
|
"est_loading_date",
|
||||||
"est_unloading_date",
|
"est_unloading_date",
|
||||||
"origin.city",
|
"origin.city",
|
||||||
"origin_geo",
|
|
||||||
"origin.state",
|
"origin.state",
|
||||||
|
"origin.lat",
|
||||||
|
"origin.lng",
|
||||||
"destination.city",
|
"destination.city",
|
||||||
"destination.state",
|
"destination.state",
|
||||||
"destination_geo",
|
"destination.lat",
|
||||||
|
"destination.lng",
|
||||||
];
|
];
|
||||||
// const load = await Model.findOne( { _id : elementId , load_status : "Transit" } , select ).populate( populate_list );
|
// const load = await Model.findOne( { _id : elementId , load_status : "Transit" } , select ).populate( populate_list );
|
||||||
const load = await Model.findById( elementId , select ).populate( populate_list );
|
const load = await Model.findById( elementId , select ).populate( populate_list );
|
||||||
|
|||||||
@@ -1,46 +1,40 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const { getPagination , getPage } = require( '../../../lib/Misc' );
|
const { getPagination , getPage } = require( '../../../lib/Misc' );
|
||||||
const { GenericHandler } = require( '../../../lib/Handlers/Generic.handler' );
|
const { GenericHandler } = require( '../../../lib/Handlers/Generic.handler' );
|
||||||
const Model = require( '../../../lib/Models/loads.model.js' );
|
const Model = require( '../../../lib/Models/loads.model.js' );
|
||||||
const categoriesModel = require( '../../../lib/Models/product-categories.model' );
|
const categoriesModel = require( '../../../lib/Models/product-categories.model' );
|
||||||
|
|
||||||
const populate_list = [
|
const populate_list = [ 'categories' ];
|
||||||
'categories',
|
// last_location_lat
|
||||||
{
|
// last_location_lng
|
||||||
path:'vehicle',
|
// last_location_geo
|
||||||
select:"last_location_lat last_location_lng last_location_geo last_location_time background_tracking"
|
// last_location_time
|
||||||
}
|
// background_tracking
|
||||||
];
|
const generic = new GenericHandler( Model, null, populate_list );
|
||||||
// last_location_lat
|
|
||||||
// last_location_lng
|
const getList = async(req, res) => {
|
||||||
// last_location_geo
|
try{
|
||||||
// last_location_time
|
const filter = { status : "Published" };
|
||||||
// background_tracking
|
const select = [
|
||||||
const generic = new GenericHandler( Model, null, populate_list );
|
"shipment_code",
|
||||||
|
"categories",
|
||||||
const getList = async(req, res) => {
|
"truck_type",
|
||||||
try{
|
"published_date",
|
||||||
const filter = { status : "Published" };
|
"createdAt",
|
||||||
const select = [
|
"status",
|
||||||
"shipment_code",
|
"weight",
|
||||||
"categories",
|
"est_loading_date",
|
||||||
"truck_type",
|
"est_unloading_date",
|
||||||
"published_date",
|
"origin",
|
||||||
"createdAt",
|
"destination"
|
||||||
"status",
|
];
|
||||||
"weight",
|
const { page , elements } = getPagination( req.query );
|
||||||
"est_loading_date",
|
const retVal = await generic.getList(page , elements, filter, select );
|
||||||
"est_unloading_date",
|
res.send( retVal );
|
||||||
"origin",
|
}catch(error){
|
||||||
"destination"
|
console.error( error );
|
||||||
];
|
return res.status( 500 ).send({ error: error.message });
|
||||||
const { page , elements } = getPagination( req.query );
|
}
|
||||||
const retVal = await generic.getList(page , elements, filter, select );
|
};
|
||||||
res.send( retVal );
|
|
||||||
}catch(error){
|
module.exports = { getList };
|
||||||
console.error( error );
|
|
||||||
return res.status( 500 ).send({ error: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = { getList };
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ const getListPublished = async(req, res) => {
|
|||||||
const getListLocations = async(req, res) => {
|
const getListLocations = async(req, res) => {
|
||||||
const filter = { status : "Free" };
|
const filter = { status : "Free" };
|
||||||
const select = [
|
const select = [
|
||||||
"last_location_geo",
|
"last_location_lat",
|
||||||
|
"last_location_lng",
|
||||||
"driver",
|
"driver",
|
||||||
"updatedAt",
|
"updatedAt",
|
||||||
"status",
|
"status",
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ async function login( email , password ){
|
|||||||
let safe_password = toSha256( password + pwd_secret );
|
let safe_password = toSha256( password + pwd_secret );
|
||||||
const user = await UserModel.findOne({
|
const user = await UserModel.findOne({
|
||||||
email , password : safe_password
|
email , password : safe_password
|
||||||
},{ password : 0 , session_token : 0 , session_token_exp : 0 }).populate('company');
|
},{ password : 0 , session_token : 0 , session_token_exp : 0 }).populate(['company','vehicle']);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ async function login_with_session_token( session_token ){
|
|||||||
const user = await UserModel.findOne({
|
const user = await UserModel.findOne({
|
||||||
session_token,
|
session_token,
|
||||||
session_token_exp : { $gte: new Date() }
|
session_token_exp : { $gte: new Date() }
|
||||||
},{ password : 0 , session_token : 0 , session_token_exp : 0 }).populate('company');
|
},{ password : 0 , session_token : 0 , session_token_exp : 0 }).populate(['company','vehicle']);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const { getPagination } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
|
|||||||
const usersModel = getModel('users');
|
const usersModel = getModel('users');
|
||||||
const companiesModel = getModel('companies');
|
const companiesModel = getModel('companies');
|
||||||
|
|
||||||
const populate_list = ['company','branch','vehicle','active_load','categories'];
|
const populate_list = ['company','branch','vehicle','categories'];
|
||||||
const generic = new GenericHandler( usersModel, "first_name", populate_list );
|
const generic = new GenericHandler( usersModel, "first_name", populate_list );
|
||||||
|
|
||||||
async function getUserById( id , filter ){
|
async function getUserById( id , filter ){
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ const schema = new Schema({
|
|||||||
|
|
||||||
vehicle: { type: Schema.Types.ObjectId, ref: 'vehicles' },
|
vehicle: { type: Schema.Types.ObjectId, ref: 'vehicles' },
|
||||||
|
|
||||||
active_load: { type: Schema.Types.ObjectId, ref: 'loads' },
|
|
||||||
|
|
||||||
categories: [{ type: Schema.Types.ObjectId, ref: 'productcategories' }],
|
categories: [{ type: Schema.Types.ObjectId, ref: 'productcategories' }],
|
||||||
user_city: [{ type: String }],
|
user_city: [{ type: String }],
|
||||||
user_state: [{ type: String }],
|
user_state: [{ type: String }],
|
||||||
|
|||||||
@@ -1,18 +1,6 @@
|
|||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const { Schema } = mongoose;
|
const { Schema } = mongoose;
|
||||||
|
|
||||||
const pointSchema = new Schema({
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
enum: ['Point'],
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
coordinates: {
|
|
||||||
type: [Number],
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const schema = new Schema({
|
const schema = new Schema({
|
||||||
company: { type: Schema.Types.ObjectId, ref: 'companies', required: true }, // carrier
|
company: { type: Schema.Types.ObjectId, ref: 'companies', required: true }, // carrier
|
||||||
company_name : { type: String, required: true },
|
company_name : { type: String, required: true },
|
||||||
@@ -50,7 +38,6 @@ const schema = new Schema({
|
|||||||
|
|
||||||
last_location_lat: { type: String },
|
last_location_lat: { type: String },
|
||||||
last_location_lng: { type: String },
|
last_location_lng: { type: String },
|
||||||
last_location_geo: { type: pointSchema },
|
|
||||||
last_location_time: { type: Date },
|
last_location_time: { type: Date },
|
||||||
createdAt: { type : Date, required : true, default : () => { return Date.now(); } }
|
createdAt: { type : Date, required : true, default : () => { return Date.now(); } }
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user