fix(Model(vehicles)): available_in is a string now

This commit is contained in:
Josepablo C
2024-08-05 06:57:29 -06:00
parent 4ad5caf3e2
commit 49ee7d7b5a
2 changed files with 11 additions and 2 deletions

View File

@@ -7,9 +7,12 @@ const vehicle_projection = ['background_tracking','status','last_location_lat',
const user_projection = ['first_name','last_name','middle_name'] const user_projection = ['first_name','last_name','middle_name']
const company_projection = ["company_name"]
const populate_list = [ const populate_list = [
{path:'posted_by',select: user_projection }, {path:'posted_by',select: user_projection },
{path:'vehicle',select: vehicle_projection }, {path:'vehicle',select: vehicle_projection },
{path:'company',select: company_projection },
'posted_by_name', 'posted_by_name',
'categories' 'categories'
]; ];
@@ -36,7 +39,13 @@ const getById = async(req, res) => {
]; ];
// 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 );
res.send( load ); if( load ){
return res.send( load );
}else{
return res.status(400).send({
error : `Load [${elementId}] not found!`
})
}
}catch(error){ }catch(error){
console.error( error ); console.error( error );
return res.status( 500 ).send({ error }); return res.status( 500 ).send({ error });

View File

@@ -41,7 +41,7 @@ const schema = new Schema({
active_load: { type: Schema.Types.ObjectId, ref: 'loads' }, active_load: { type: Schema.Types.ObjectId, ref: 'loads' },
load_shipper: { type: Schema.Types.ObjectId, ref: 'companies' }, load_shipper: { type: Schema.Types.ObjectId, ref: 'companies' },
available_in: [{ type: String }], available_in: { type: String },
destino: { type: String }, destino: { type: String },
driver: { type: Schema.Types.ObjectId, ref: 'users' }, driver: { type: Schema.Types.ObjectId, ref: 'users' },