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