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 ){
|
||||
const filter = {
|
||||
$and : [
|
||||
{ _id : elementId },
|
||||
{
|
||||
$or : [
|
||||
{ company : companyId },
|
||||
{ carrier : companyId }
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
let retVal = await Model.findOne( filter ).populate( populate_list );
|
||||
async function findElementById( elementId ){
|
||||
let retVal = await Model.findById( elementId ).populate( populate_list );
|
||||
if( retVal ){
|
||||
retVal = retVal.toObject();
|
||||
const no_of_proposals = await ProposalsModel.count({ load : elementId });
|
||||
@@ -99,9 +88,8 @@ const findList = async(req, res) => {
|
||||
|
||||
const getById = async(req, res) => {
|
||||
try{
|
||||
const companyId = req.context.companyId;
|
||||
const elementId = req.params.id;
|
||||
res.send( await findElementById( elementId , companyId ) );
|
||||
res.send( await findElementById( elementId ) );
|
||||
}catch(error){
|
||||
console.error( error );
|
||||
return res.status( 500 ).send({ error });
|
||||
@@ -110,11 +98,10 @@ const getById = async(req, res) => {
|
||||
|
||||
const patchLoad = async(req, res) => {
|
||||
try{
|
||||
const companyId = req.context.companyId;
|
||||
const elementId = req.params.id;
|
||||
const permissions = req.context.permissions;
|
||||
const data = req.body;
|
||||
const load = await findElementById( elementId , companyId );
|
||||
const load = await findElementById( elementId );
|
||||
if( !load ){
|
||||
throw "You can't modify this load";
|
||||
}
|
||||
@@ -124,7 +111,6 @@ const patchLoad = async(req, res) => {
|
||||
if(permissions !== "role_shipper" ){
|
||||
throw "You can't modify loads";
|
||||
}
|
||||
data.company = companyId;
|
||||
await Model.findByIdAndUpdate( elementId , data );
|
||||
return res.send( await Model.findById( elementId ) );
|
||||
}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