diff --git a/v1/src/apps/private/vehicles/services.js b/v1/src/apps/private/vehicles/services.js index 632b042..bbdb08a 100644 --- a/v1/src/apps/private/vehicles/services.js +++ b/v1/src/apps/private/vehicles/services.js @@ -4,6 +4,7 @@ const { getModel } = require( `${ROOT_PATH}/${MODELS_PATH}` ); const { getPagination } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` ); const { GenericHandler } = require( `${ROOT_PATH}/${HANDLERS_PATH}/Generic.handler.js` ); const Model = getModel('vehicles'); +const CompanyModel = getModel('companies'); const populate_list = ['categories', 'active_load','load_shipper','driver']; const generic = new GenericHandler( Model, null, populate_list ); @@ -12,6 +13,7 @@ function getAndFilterList( query ){ const filter_list = []; const { company, + company_name, is_available, categories, active_load, @@ -30,6 +32,7 @@ function getAndFilterList( query ){ } = query; if( company ) { filter_list.push({ company }); } + if( company_name ) { filter_list.push({ company_name }); } if( is_available ) { filter_list.push({ is_available }); } if( categories ) { filter_list.push({ categories }); } if( active_load ) { filter_list.push({ active_load }); } @@ -135,6 +138,7 @@ const patchVehicle = async(req, res) => { const companyId = req.context.companyId; const elementId = req.params.id; const permissions = req.context.permissions; + const company = await CompanyModel.findById( companyId ); const vehicle = await findElementById( elementId , companyId ); const data = req.body; if( !vehicle ){ @@ -146,7 +150,9 @@ const patchVehicle = async(req, res) => { if( permissions !== "role_carrier" ){ throw "You can't modify vehicles"; } + data.company = companyId; + data.company_name = company.name; await Model.findByIdAndUpdate( elementId , data ); return res.send( await Model.findById( elementId ) ); }catch(error){ @@ -159,6 +165,7 @@ const postVehicle = async(req, res) => { try{ const userId = req.context.userId; const companyId = req.context.companyId; + const company = await CompanyModel.findById( companyId ); const permissions = req.context.permissions; const data = req.body; if( !data ){ @@ -167,7 +174,9 @@ const postVehicle = async(req, res) => { if(permissions !== "role_carrier" ){ throw "You can't create vehicles"; } + data.company = companyId; + data.company_name = company.name; data.status = "Free"; data.is_available = false; data.posted_by = userId; diff --git a/v1/src/lib/Models/vehicles.model.js b/v1/src/lib/Models/vehicles.model.js index d3b69cc..4be1504 100644 --- a/v1/src/lib/Models/vehicles.model.js +++ b/v1/src/lib/Models/vehicles.model.js @@ -15,6 +15,7 @@ const pointSchema = new Schema({ const schema = new Schema({ company: { type: Schema.Types.ObjectId, ref: 'companies', required: true }, // carrier + company_name : { type: String }, vehicle_code: { type: String }, vehicle_name: { type: String },