fix: Remove role based queries, simplify API
This commit is contained in:
@@ -62,19 +62,8 @@ async function findLoads( companyId , query ){
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findElementById( elementId , companyId ){
|
async function findElementById( elementId ){
|
||||||
const filter = {
|
let retVal = await Model.findById( elementId ).populate( populate_list );
|
||||||
$and : [
|
|
||||||
{ _id : elementId },
|
|
||||||
{
|
|
||||||
$or : [
|
|
||||||
{ company : companyId },
|
|
||||||
{ carrier : companyId }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
let retVal = await Model.findOne( filter ).populate( populate_list );
|
|
||||||
if( retVal ){
|
if( retVal ){
|
||||||
retVal = retVal.toObject();
|
retVal = retVal.toObject();
|
||||||
const no_of_proposals = await ProposalsModel.count({ load : elementId });
|
const no_of_proposals = await ProposalsModel.count({ load : elementId });
|
||||||
@@ -99,9 +88,8 @@ const findList = async(req, res) => {
|
|||||||
|
|
||||||
const getById = async(req, res) => {
|
const getById = async(req, res) => {
|
||||||
try{
|
try{
|
||||||
const companyId = req.context.companyId;
|
|
||||||
const elementId = req.params.id;
|
const elementId = req.params.id;
|
||||||
res.send( await findElementById( elementId , companyId ) );
|
res.send( await findElementById( elementId ) );
|
||||||
}catch(error){
|
}catch(error){
|
||||||
console.error( error );
|
console.error( error );
|
||||||
return res.status( 500 ).send({ error });
|
return res.status( 500 ).send({ error });
|
||||||
@@ -110,11 +98,10 @@ const getById = async(req, res) => {
|
|||||||
|
|
||||||
const patchLoad = async(req, res) => {
|
const patchLoad = async(req, res) => {
|
||||||
try{
|
try{
|
||||||
const companyId = req.context.companyId;
|
|
||||||
const elementId = req.params.id;
|
const elementId = req.params.id;
|
||||||
const permissions = req.context.permissions;
|
const permissions = req.context.permissions;
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
const load = await findElementById( elementId , companyId );
|
const load = await findElementById( elementId );
|
||||||
if( !load ){
|
if( !load ){
|
||||||
throw "You can't modify this load";
|
throw "You can't modify this load";
|
||||||
}
|
}
|
||||||
@@ -124,7 +111,6 @@ const patchLoad = async(req, res) => {
|
|||||||
if(permissions !== "role_shipper" ){
|
if(permissions !== "role_shipper" ){
|
||||||
throw "You can't modify loads";
|
throw "You can't modify loads";
|
||||||
}
|
}
|
||||||
data.company = companyId;
|
|
||||||
await Model.findByIdAndUpdate( elementId , data );
|
await Model.findByIdAndUpdate( elementId , data );
|
||||||
return res.send( await Model.findById( elementId ) );
|
return res.send( await Model.findById( elementId ) );
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
|||||||
14
test/lib/handlers/proposals/common.test.js
Normal file
14
test/lib/handlers/proposals/common.test.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
/// System implementation dependences
|
||||||
|
require('dotenv').config();
|
||||||
|
/// Unit testing dependences
|
||||||
|
const assert = require("assert");
|
||||||
|
|
||||||
|
|
||||||
|
describe('Example' , () => {
|
||||||
|
it('finds list', async () => {
|
||||||
|
assert.equal( 0,0 );
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user