fix: Adding categories field to loads
- Adding company/carrier as mandatory fields for load-attachments. - Adding categories field to loads.
This commit is contained in:
@@ -30,16 +30,20 @@ async function getAuthorizationFilter( userId ){
|
||||
}
|
||||
|
||||
const getAttachment = async(req, res) => {
|
||||
const attachmentId = req.params.id;
|
||||
const CompanyAccessFilter = await getAuthorizationFilter( req.JWT.payload.sub );
|
||||
const filter = {
|
||||
$and : [
|
||||
{ _id : attachmentId },
|
||||
CompanyAccessFilter
|
||||
]
|
||||
};
|
||||
const retVal = await Model.findOne( filter ) || {};
|
||||
res.send( retVal );
|
||||
try{
|
||||
const attachmentId = req.params.id;
|
||||
const CompanyAccessFilter = await getAuthorizationFilter( req.JWT.payload.sub );
|
||||
const filter = {
|
||||
$and : [
|
||||
{ _id : attachmentId },
|
||||
CompanyAccessFilter
|
||||
]
|
||||
};
|
||||
const retVal = await Model.findOne( filter ) || {};
|
||||
res.send( retVal );
|
||||
}catch( err ){
|
||||
res.send( {} );
|
||||
}
|
||||
};
|
||||
|
||||
const getAttachmentList = async(req, res) => {
|
||||
@@ -50,18 +54,27 @@ const getAttachmentList = async(req, res) => {
|
||||
};
|
||||
|
||||
const getLoadAttachmentList = async(req, res) => {
|
||||
const loadId = req.params.id;
|
||||
const CompanyAccessFilter = await getAuthorizationFilter( req.JWT.payload.sub );
|
||||
console.log( loadId );
|
||||
const filter = {
|
||||
$and : [
|
||||
{ load : loadId },
|
||||
CompanyAccessFilter
|
||||
]
|
||||
};
|
||||
const { page , elements } = getPagination( req.query );
|
||||
const retVal = await getPage( page, elements, Model, filter );
|
||||
res.send( retVal );
|
||||
const loadId = req.params.id;
|
||||
try{
|
||||
const CompanyAccessFilter = await getAuthorizationFilter( req.JWT.payload.sub );
|
||||
const filter = {
|
||||
$and : [
|
||||
{ load : loadId },
|
||||
CompanyAccessFilter
|
||||
]
|
||||
};
|
||||
const retVal = await getPage( page, elements, Model, filter );
|
||||
return res.send( retVal );
|
||||
}catch( error ){
|
||||
console.log( error );
|
||||
return res.send({
|
||||
total: 0,
|
||||
limit: elements,
|
||||
skip: page*elements,
|
||||
data : []
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
async function getLoadById( loadId , companyId ){
|
||||
@@ -91,6 +104,7 @@ async function createLoadAttachment( type , userId , loadId ){
|
||||
attachment = new Model({
|
||||
type : type,
|
||||
carrier : companyId,
|
||||
company : load.company,
|
||||
load : loadId,
|
||||
author : userId
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ const CompaniesModel = require( `${ROOT_PATH}/${MODELS_PATH}/companies.model.js`
|
||||
const VehiclesModel = require( `${ROOT_PATH}/${MODELS_PATH}/vehicles.model.js` );
|
||||
const ProposalsModel = require( `${ROOT_PATH}/${MODELS_PATH}/proposals.model.js` );
|
||||
|
||||
const populate_list = ['product', 'company', 'carrier', 'vehicle'];
|
||||
const populate_list = ['product', 'company', 'carrier', 'vehicle', 'categories'];
|
||||
const generic = new GenericHandler( Model, null, populate_list );
|
||||
|
||||
async function getAuthorizationFilter( userId ){
|
||||
|
||||
@@ -8,7 +8,7 @@ const schema = new Schema({
|
||||
default : () => Date.now()
|
||||
},
|
||||
type: { type: String, enum: ['Loading', 'Downloading'], required : true },
|
||||
company: { type: Schema.Types.ObjectId, ref: 'companies' }, //shipper
|
||||
company: { type: Schema.Types.ObjectId, ref: 'companies', required: true }, //shipper
|
||||
carrier: { type: Schema.Types.ObjectId, ref: 'companies', required: true }, // carrier
|
||||
load: { type: Schema.Types.ObjectId, ref: 'loads', required: true },
|
||||
author: { type: Schema.Types.ObjectId, ref: 'users', required: true },
|
||||
|
||||
Reference in New Issue
Block a user