fix(loads): Normalize dates on post and patch (remove time from dates)

This commit is contained in:
Josepablo C
2025-07-21 12:07:46 -06:00
parent c9d5566288
commit 43bcc7c0f3
72 changed files with 118 additions and 3273 deletions

View File

@@ -12,11 +12,18 @@ const proposalsModel = getModel('proposals');
*/
async function onDelivered( userId, elementId ){
const load = await loadsModel.findById( elementId );
if( !load ){
/// Nothing to do, invalid load
return;
}
const proposal_list = await proposalsModel.find({
load: elementId,
is_accepted: true,
is_completed: false
});
const vehicle_list = await vehiclesModel.find({
active_load: elementId
});

View File

@@ -39,6 +39,19 @@ function genKey( len = 6, key="" ){
return otp_str.slice(0,len);
}
/**
* Takes a datetime input and produces a date only output.
* @param {*} date
*/
function normalizeDate( date ){
let in_date = new Date( date );
let year = in_date.getFullYear();
let monthIndex = in_date.getMonth();
let day = in_date.getDate();
// new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds);
return new Date( year, monthIndex, day, 0, 0, 0, 0 );
}
function getPagination( query ){
let limit = {
page : 0,
@@ -101,4 +114,4 @@ async function downloadFile( bucket, key, obj_id ){
return s3resp;
}
module.exports = { genKey , toSha256, getPagination, getPage, queryPage, downloadFile};
module.exports = { genKey , toSha256, normalizeDate, getPagination, getPage, queryPage, downloadFile};