fix(loads/find): Adding est_loading_date field to the find query

This commit is contained in:
Josepablo C
2025-04-08 23:22:11 -06:00
parent 5e55b0f738
commit 4da61abb73
2 changed files with 18 additions and 1 deletions

View File

@@ -374,6 +374,8 @@ This endpoint is part of /loads endpoint
- product
- shipment_code
- shipper_warehouse : id of a company branch
- est_loading_date[gte] : Date greater than.
- est_loading_date[lte] : Date less than.
- company_name[$regex] : Regex string to find company_name
- company_name[$options] : Regex options from MongoDB filter description
- $sort[ field ] : -1/1 ; Sort result by field name

View File

@@ -54,7 +54,8 @@ function getAndFilterList( query ){
categories,
product,
shipment_code,
shipper_warehouse
shipper_warehouse,
est_loading_date
} = query;
if( company ){ filter_list.push( { company } ); }
@@ -72,6 +73,20 @@ function getAndFilterList( query ){
if( product ) { filter_list.push({ product }); }
if( shipment_code ) { filter_list.push({ shipment_code }); }
if( shipper_warehouse ) { filter_list.push({ shipper_warehouse }); }
if( est_loading_date ) {
if( (est_loading_date.gte == undefined) || (est_loading_date.gte == null) ){
throw "est_loading_date[gte] is required";
}
if( (est_loading_date.lte == undefined) || (est_loading_date.lte == null) ){
throw "est_loading_date[lte] is required";
}
filter_list.push({
"est_loading_date" : {
$gte : new Date( est_loading_date["gte"] ),
$lte : new Date( est_loading_date["lte"] )
}
});
}
if( filter_list.length == 0 ){
return null;