fix(proposals): Allow finding proposals from any company

This commit is contained in:
Josepablo C
2024-04-05 21:21:13 -06:00
parent eb08f4abb8
commit 857ca28f43
2 changed files with 178 additions and 185 deletions

View File

@@ -11,8 +11,9 @@ const generic = new GenericHandler( Model, null, populate_list );
function getAndFilterList( query ){ function getAndFilterList( query ){
const filter_list = []; const filter_list = [];
const { categories, branch_name, phone, city, state, truck_type } = query; const { load, categories, branch_name, phone, city, state, truck_type } = query;
if( load ) { filter_list.push({ load }); }
if( categories ) { filter_list.push({ categories }); } if( categories ) { filter_list.push({ categories }); }
if( branch_name ) { filter_list.push({ branch_name }); } if( branch_name ) { filter_list.push({ branch_name }); }
if( phone ) { filter_list.push({ phone }); } if( phone ) { filter_list.push({ phone }); }
@@ -26,21 +27,14 @@ function getAndFilterList( query ){
return filter_list; return filter_list;
} }
async function findElements( companyId , query ){ async function findElements( query ){
const { page, elements } = getPagination( query ); const { page, elements } = getPagination( query );
const andFilterList = getAndFilterList( query ); const andFilterList = getAndFilterList( query );
let filter; let filter;
if( andFilterList ){ if( andFilterList ){
andFilterList.push({ $or :[
{ shipper : companyId },
{ carrier : companyId }
]});
filter = { $and : andFilterList }; filter = { $and : andFilterList };
}else{ }else{
filter = { $or :[ filter = null;
{ shipper : companyId },
{ carrier : companyId }
]};
} }
const { total , limit, skip, data } = await generic.getList( page , elements, filter ); const { total , limit, skip, data } = await generic.getList( page , elements, filter );
return { return {
@@ -68,8 +62,7 @@ async function findElementById( elementId , companyId ){
const findList = async(req, res) => { const findList = async(req, res) => {
try{ try{
const query = req.query || {}; const query = req.query || {};
const companyId = req.context.companyId; const retVal = await findElements( query );
const retVal = await findElements( companyId , query );
res.send( retVal ); res.send( retVal );
}catch(error){ }catch(error){
console.error( error ); console.error( error );