Merge pull request 'feat(travelFilter): add daysOnward' (!3008) from hotFix_travelList_daysOnward into test
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3008
Reviewed-by: Jorge Penadés <jorgep@verdnatura.es>
This commit is contained in:
Alex Moreno 2024-09-24 10:21:54 +00:00
commit 45a016065d
1 changed files with 15 additions and 2 deletions

View File

@ -79,6 +79,10 @@ module.exports = Self => {
arg: 'landingHour',
type: 'string',
description: 'The landing hour'
}, {
arg: 'daysOnward',
type: 'number',
description: 'The days onward'
}
],
returns: {
@ -92,8 +96,11 @@ module.exports = Self => {
});
Self.filter = async(ctx, filter) => {
let conn = Self.dataSource.connector;
let where = buildFilter(ctx.args, (param, value) => {
const conn = Self.dataSource.connector;
const today = Date.vnNew();
const future = Date.vnNew();
const where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'search':
return /^\d+$/.test(value)
@ -109,6 +116,12 @@ module.exports = Self => {
return {'t.landed': {gte: value}};
case 'landedTo':
return {'t.landed': {lte: value}};
case 'daysOnward':
today.setHours(0, 0, 0, 0);
future.setDate(today.getDate() + value);
future.setHours(23, 59, 59, 999);
return {'t.landed': {between: [today, future]}};
case 'id':
case 'agencyModeFk':
case 'warehouseOutFk':