feat: Adding filters to public-companies
This commit is contained in:
@@ -26,6 +26,23 @@ function join_field_list( obj_with_fields , list_of_fields )
|
||||
return obj_with_fields;
|
||||
}
|
||||
|
||||
function getAndFilterList( query ){
|
||||
const filter_list = [];
|
||||
const { company_type, company_name, truck_type, categories, company_state, company_city } = query;
|
||||
|
||||
if( company_name ){ filter_list.push( { company_name } ); }
|
||||
if( company_type ){ filter_list.push( { company_type } ); }
|
||||
if( company_state ){ filter_list.push( { company_state } ); }
|
||||
if( company_city ){ filter_list.push( { company_city } ); }
|
||||
if( truck_type ){ filter_list.push( { truck_type } ); }
|
||||
if( categories ){ filter_list.push( { categories } ); }
|
||||
|
||||
if( filter_list.length == 0 ){
|
||||
return null;
|
||||
}
|
||||
return filter_list;
|
||||
}
|
||||
|
||||
async function getListByType( type , req ){
|
||||
const filter = { "company_type" : type , "is_hidden" : false };
|
||||
const select = [
|
||||
@@ -49,6 +66,13 @@ async function getListByType( type , req ){
|
||||
}else{
|
||||
query_elements = elements;
|
||||
}
|
||||
|
||||
const andFilterList = getAndFilterList( req.query );
|
||||
|
||||
if( andFilterList ){
|
||||
filter.$and = andFilterList;
|
||||
}
|
||||
|
||||
const queryVal = await generic.getList(page , query_elements, filter, select );
|
||||
const data_list = queryVal.data;
|
||||
for(let i=0; i<data_list.length; i++){
|
||||
@@ -75,13 +99,23 @@ async function getListByType( type , req ){
|
||||
}
|
||||
|
||||
const getListShippers = async(req, res) => {
|
||||
try{
|
||||
const retVal = await getListByType( "Shipper" , req );
|
||||
res.send( retVal );
|
||||
} catch ( err ){
|
||||
console.error( err );
|
||||
return res.status(500).send({ error : "Public-Companies(Carriers): Internal error" });
|
||||
}
|
||||
};
|
||||
|
||||
const getListCarriers = async(req, res) => {
|
||||
try{
|
||||
const retVal = await getListByType( "Carrier" , req );
|
||||
res.send( retVal );
|
||||
} catch ( err ){
|
||||
console.error( err );
|
||||
return res.status(500).send({ error : "Public-Companies(Carriers): Internal error" });
|
||||
}
|
||||
};
|
||||
|
||||
const getUserLists = async(req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user