From 1d47690bb49515d8d3871a550b917bc6837d3e61 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 17 Sep 2024 08:31:58 +0200 Subject: [PATCH] feat: refs #7884 added new filter field --- modules/entry/back/methods/entry/filter.js | 22 +++++++++++++--- .../back/methods/entry/specs/filter.spec.js | 25 +++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 776544bc6..60b58864b 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -106,10 +106,15 @@ module.exports = Self => { description: `The to shipped date filter` }, { - arg: 'days', + arg: 'daysOnward', type: 'number', description: `N days interval` }, + { + arg: 'daysAgo', + type: 'number', + description: `N days ago interval` + }, { arg: 'invoiceAmount', type: 'number', @@ -216,15 +221,26 @@ module.exports = Self => { JOIN vn.currency cu ON cu.id = e.currencyFk` ); - if (ctx.args.days) { + if (ctx.args.daysOnward) { stmt.merge({ sql: ` AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY AND t.shipped >= util.VN_CURDATE() `, - params: [ctx.args.days] + params: [ctx.args.daysOnward] }); } + + if (ctx.args.daysAgo) { + stmt.merge({ + sql: ` + AND t.shipped >= util.VN_CURDATE() - INTERVAL ? DAY + AND t.shipped < util.VN_CURDATE() + `, + params: [ctx.args.daysAgo] + }); + } + 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..105838858 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -49,13 +49,13 @@ describe('Entry filter()', () => { }); describe('should return the entry matching the supplier', () => { - it('when userId is supplier ', async() => { + it('when userId is supplier and searching days onward', async() => { const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; try { const ctx = { - args: {days: 6}, + args: {daysOnward: 6}, req: {accessToken: {userId: 1102}} }; @@ -70,6 +70,27 @@ describe('Entry filter()', () => { } }); + it('when userId is supplier and searching days ago', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: {daysAgo: 31}, + req: {accessToken: {userId: 1102}} + }; + + const result = await models.Entry.filter(ctx, options); + + expect(result.length).toEqual(6); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + it('when userId is supplier fetching other supplier', async() => { const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx};