fix(Calendar): Adding global and date filter patch

This commit is contained in:
Josepablo C
2024-07-22 19:46:52 -06:00
parent 4bd9549f5e
commit a2d9c48396
2 changed files with 18 additions and 8 deletions

View File

@@ -378,6 +378,7 @@ This endpoint is part of /loads endpoint
- date[gte] : Date grater than.
- date[lte] : Date less than.
- load_status : string enumerator ['Published', 'Loading', 'Transit', 'Downloading', 'Delivered'].
- global : 1 To return calendar of all company, or 0/undefined for personal calendar only.
- $sort[ field ] : -1/1 ; Sort result by field name
- `POST /new` : Creates a new element.
- `PATCH /:id` : Updates data from specific element.

View File

@@ -105,29 +105,38 @@ async function findCalendarLoads( userId, companyId, query ){
"transit_date",
"delivered_date",
"createdAt",
"shipment_code"
"shipment_code",
"est_loading_date",
"est_unloading_date"
];
const { date, load_status , $sort } = query;
const { global } = query;
if( ! date ){
throw "Date field is required";
}
const { page, elements } = getPagination( query );
const orFilterList = [
{"company" : companyId},
{"carrier" : companyId}
]
if( !global ){
orFilterList.push( {"bidder" : userId} );
orFilterList.push( {"posted_by" : userId} );
}
const andFilterList = [
{
"load_status_updated" : {
"est_loading_date" : {
$gte : new Date( date["gte"] ),
$lte : new Date( date["lte"] )
}
},
{
$or : [
{"bidder" : userId},
{"posted_by" : userId},
{"company" : companyId},
{"carrier" : companyId}
]
$or : orFilterList
}
]