From 151b26ae8b83b833cb4e6cd88cd02495862b6bb6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 21 Aug 2024 13:23:03 +0000 Subject: [PATCH 1/2] feat(salix): #7884 add new param --- modules/entry/back/methods/entry/filter.js | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index dcb1e3158..e3b14b3a2 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -106,9 +106,14 @@ module.exports = Self => { description: `The to shipped date filter` }, { - arg: 'days', + arg: 'daysAfter', type: 'number', - description: `N days interval` + description: `N days after interval` + }, + { + arg: 'daysBefore', + type: 'number', + description: `N days before interval` } ], returns: { @@ -210,15 +215,25 @@ module.exports = Self => { JOIN vn.currency cu ON cu.id = e.currencyFk` ); - if (ctx.args.days) { + if (ctx.args.daysAfter) { stmt.merge({ sql: ` - AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY - AND t.shipped >= util.VN_CURDATE() + AND ((t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY + AND t.shipped>= util.VN_CURDATE()) `, - params: [ctx.args.days] + params: [ctx.args.daysAfter] }); } + if (ctx.args.daysBefore) { + stmt.merge({ + sql: ` + ${ctx.args.daysAfter ? 'OR' : 'AND'} (t.shipped <= util.VN_CURDATE() + AND t.shipped >= util.VN_CURDATE() - INTERVAL ? DAY) + `, + params: [ctx.args.daysBefore] + }); + } + stmt.merge({sql: ')'}); stmt.merge(conn.makeSuffix(filter)); const itemsIndex = stmts.push(stmt) - 1; -- 2.40.1 From 2aec9db824f275b72f8a388ce01f703422909ba9 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 21 Aug 2024 20:48:00 +0200 Subject: [PATCH 2/2] test: refs #7884 change days by daysAfter --- modules/entry/back/methods/entry/filter.js | 2 +- modules/entry/back/methods/entry/specs/filter.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index e3b14b3a2..4926ad88f 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -233,7 +233,7 @@ module.exports = Self => { params: [ctx.args.daysBefore] }); } - stmt.merge({sql: ')'}); + if (ctx.args.daysAfter) stmt.merge({sql: ')'}); stmt.merge(conn.makeSuffix(filter)); const itemsIndex = stmts.push(stmt) - 1; diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index c7156062a..9007deeef 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -55,7 +55,7 @@ describe('Entry filter()', () => { try { const ctx = { - args: {days: 6}, + args: {daysAfter: 6}, req: {accessToken: {userId: 1102}} }; -- 2.40.1