From f6edb0ea9a465ea4ce1ed6007389a18276a4b0a2 Mon Sep 17 00:00:00 2001 From: Josepablo C Date: Wed, 27 Mar 2024 23:01:53 -0600 Subject: [PATCH] fix: Remove role based queries, simplify API --- src/apps/private/loads/services.js | 22 ++++------------------ test/lib/handlers/proposals/common.test.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 test/lib/handlers/proposals/common.test.js diff --git a/src/apps/private/loads/services.js b/src/apps/private/loads/services.js index 97fcfd2..5d5cf31 100644 --- a/src/apps/private/loads/services.js +++ b/src/apps/private/loads/services.js @@ -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){ diff --git a/test/lib/handlers/proposals/common.test.js b/test/lib/handlers/proposals/common.test.js new file mode 100644 index 0000000..832474b --- /dev/null +++ b/test/lib/handlers/proposals/common.test.js @@ -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 ); + }) +}); + +