feat: Adding loads and load-attachments endpoints
This commit is contained in:
@@ -27,8 +27,8 @@ function getPagination( query ){
|
||||
|
||||
async function queryPage( page, elements, model, filter=null, projection=null){
|
||||
const skip = elements * page;
|
||||
const total = await model.count();
|
||||
const list = await model.find( filter, projection, { skip : skip , limit : elements } );
|
||||
const total = await model.count( filter );
|
||||
const list = await model.find( filter , projection, { skip : skip , limit : elements } );
|
||||
return {
|
||||
total : total,
|
||||
limit : elements,
|
||||
|
||||
19
lib/Models/load-attachments.model.js
Normal file
19
lib/Models/load-attachments.model.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const mongoose = require('mongoose');
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const schema = new Schema({
|
||||
status: { type: String, default: 'Draft', enum: ['Draft', 'Done'] },/*Once in Done state, no changes are allowed.*/
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default : () => Date.now()
|
||||
},
|
||||
type: { type: String, enum: ['Loading', 'Downloading'], required : true },
|
||||
company: { type: Schema.Types.ObjectId, ref: 'companies' }, //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 },
|
||||
doneAt: { type: Date }
|
||||
});
|
||||
|
||||
module.exports = mongoose.model( "loadattachments", schema );
|
||||
|
||||
@@ -50,7 +50,7 @@ const schema = new Schema({
|
||||
type: pointSchema,
|
||||
},
|
||||
|
||||
categories: [{ type: Schema.Types.ObjectId, ref: 'product-categories' }],
|
||||
categories: [{ type: Schema.Types.ObjectId, ref: 'productcategories' }],
|
||||
product: { type: Schema.Types.ObjectId, ref: 'products' },
|
||||
|
||||
truck_type: { type: String },
|
||||
@@ -80,7 +80,7 @@ const schema = new Schema({
|
||||
loaded_date: { type: Date },
|
||||
transit_date: { type: Date },
|
||||
delivered_date: { type: Date },
|
||||
load_status_updated: { type: Date, default: Date.now() },
|
||||
load_status_updated: { type: Date, default: () => Date.now() },
|
||||
notes: { type: String },
|
||||
|
||||
payment_term: { type: String },
|
||||
|
||||
@@ -7,11 +7,15 @@ const jwtSecret = apiConfig.authentication.jwtSecret;
|
||||
function middleware( req, res, next ){
|
||||
if( req.JWT ){
|
||||
req.JWT.isValid = false;
|
||||
req.JWT.payload = jwt.verify( req.JWT.raw, jwtSecret );
|
||||
if( !req.JWT.payload ){
|
||||
try{
|
||||
req.JWT.payload = jwt.verify( req.JWT.raw, jwtSecret );
|
||||
if( !req.JWT.payload ){
|
||||
return res.status(401).send({error:"Unauthorized",code:401});
|
||||
}else{
|
||||
req.JWT.isValid = true;
|
||||
}
|
||||
}catch( err ){
|
||||
return res.status(401).send({error:"Unauthorized",code:401});
|
||||
}else{
|
||||
req.JWT.isValid = true;
|
||||
}
|
||||
next();
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user