feat(Carrier::Loads): Allow find list of private loads by default

This commit is contained in:
Josepablo Cruz
2026-04-03 13:17:43 -06:00
parent 8f64b9f304
commit 89146e0aaf

View File

@@ -65,6 +65,7 @@ function getAndFilterList( query ){
truck_type, truck_type,
state, state,
city, city,
privacy,
} = query; } = query;
if( company ){ filter_list.push( { company } ); } if( company ){ filter_list.push( { company } ); }
@@ -85,6 +86,7 @@ function getAndFilterList( query ){
if( destination_warehouse ) { filter_list.push({ destination_warehouse }); } if( destination_warehouse ) { filter_list.push({ destination_warehouse }); }
if( alert_list ) { filter_list.push({ alert_list }); } if( alert_list ) { filter_list.push({ alert_list }); }
if( truck_type ) { filter_list.push({ truck_type }); } if( truck_type ) { filter_list.push({ truck_type }); }
if( privacy ) { filter_list.push({ privacy }); }
if( state ) { if( state ) {
filter_list.push({ filter_list.push({
@@ -158,25 +160,19 @@ async function findLoads( companyId, query ){
const { $sort, company_name } = query; const { $sort, company_name } = query;
const { page, elements } = getPagination( query ); const { page, elements } = getPagination( query );
const andFilterList = getAndFilterList( query ) || []; const andFilterList = getAndFilterList( query ) || [];
/// Get list of companyIds that gave authorization to see the loads
const { privacy } = query; const companiesIds = await getCompanyIdListFromGroups( companyId ) || [];
const privacyVal = ( privacy && ( privacy >= 1 || privacy.toLowerCase() === 'true' ))? true: false;
let filter = {}; let filter = {};
if( privacyVal ){
const companiesIds = await getCompanyIdListFromGroups( companyId ) || [];
filter = {
company : { $in : companiesIds },
privacy: true,
}
}else{
filter = { filter = {
$or : [ $or : [
{ privacy : false }, { privacy : false },
{ privacy : { $exists : false } } { privacy : { $exists : false } },
] {
company : { $in : companiesIds },
privacy: true
} }
]
} }
if( company_name ){ if( company_name ){