fix(vehicles/loads): fix city/state find filters

This commit is contained in:
Josepablo C
2025-07-21 13:02:07 -06:00
parent 43bcc7c0f3
commit 8ae13017be
4 changed files with 37 additions and 9 deletions

View File

@@ -459,7 +459,8 @@ __This endpoint is only valid for carriers.__
- city,
- state,
- status,
- destino
- destino,
- available_in[$regex],
- $sort[ field ] : -1/1 ; Sort result by field name
- `GET /global/find` : Find a list of elements (from all the system) with any of the following fields:
- company, (company id)

View File

@@ -61,6 +61,9 @@ function getAndFilterList( query ){
est_loading_date,
est_unloading_date,
alert_list,
truck_type,
state,
city,
} = query;
if( company ){ filter_list.push( { company } ); }
@@ -80,6 +83,26 @@ function getAndFilterList( query ){
if( origin_warehouse ) { filter_list.push({ origin_warehouse }); }
if( destination_warehouse ) { filter_list.push({ destination_warehouse }); }
if( alert_list ) { filter_list.push({ alert_list }); }
if( truck_type ) { filter_list.push({ truck_type }); }
if( state ) {
filter_list.push({
$or:[
{ "origin.state": state },
{ "destination.state": state },
]
});
}
if( city ) {
filter_list.push({
$or:[
{ "origin.city": city },
{ "destination.city": city },
]
});
}
if( est_loading_date ) {
if( (est_loading_date.gte == undefined) || (est_loading_date.gte == null) ){
throw "est_loading_date[gte] is required";
@@ -89,8 +112,8 @@ function getAndFilterList( query ){
}
filter_list.push({
"est_loading_date" : {
$gte : new Date( est_loading_date["gte"] ),
$lte : new Date( est_loading_date["lte"] )
$gte : normalizeDate( est_loading_date["gte"] ),
$lte : normalizeDate( est_loading_date["lte"] )
}
});
}
@@ -104,8 +127,8 @@ function getAndFilterList( query ){
}
filter_list.push({
"est_unloading_date" : {
$gte : new Date( est_unloading_date["gte"] ),
$lte : new Date( est_unloading_date["lte"] )
$gte : normalizeDate( est_unloading_date["gte"] ),
$lte : normalizeDate( est_unloading_date["lte"] )
}
});
}
@@ -141,6 +164,8 @@ async function findLoads( query ){
filter = null;
}
console.log( andFilterList );
const { total , limit, skip, data } = await generic.getList( page , elements, filter, null, $sort );
const load_list = data;
@@ -182,8 +207,8 @@ async function findCalendarLoads( userId, companyId, query ){
const andFilterList = [
{
"est_loading_date" : {
$gte : new Date( date["gte"] ),
$lte : new Date( date["lte"] )
$gte : normalizeDate( date["gte"] ),
$lte : normalizeDate( date["lte"] )
}
},
{

View File

@@ -33,7 +33,8 @@ function getAndFilterList( query ){
city,
state,
status,
destino
destino,
available_in
} = query;
if( company ) { filter_list.push({ company }); }
@@ -53,6 +54,7 @@ function getAndFilterList( query ){
if( state ) { filter_list.push({ state }); }
if( status ) { filter_list.push({ status }); }
if( destino ) { filter_list.push({ destino }); }
if( available_in ) { filter_list.push({ available_in }); }
if( filter_list.length == 0 ){
return null;

View File

@@ -16,7 +16,7 @@
}
},
"version" : {
"version" : "1.5.2",
"version" : "1.5.3",
"name": "ETA Beta",
"date":"21/07/2025"
},