From 6f4a12e50f37fff49c009e3d1a8cc08d34b85f92 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Sep 2023 14:42:47 +0200 Subject: [PATCH 1/5] ref #5417 date filters added --- .../methods/client/specs/transactions.spec.js | 23 +++++++++++++++++++ .../back/methods/client/transactions.js | 20 ++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/modules/client/back/methods/client/specs/transactions.spec.js b/modules/client/back/methods/client/specs/transactions.spec.js index 45fffc1de9..679eb196cc 100644 --- a/modules/client/back/methods/client/specs/transactions.spec.js +++ b/modules/client/back/methods/client/specs/transactions.spec.js @@ -63,4 +63,27 @@ describe('Client transactions', () => { throw e; } }); + + it('should call transactions() method filtering by date', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + const ctx = {args: {from: '2000/12/31'}}; + const filter = {}; + const withResults = await models.Client.transactions(ctx, filter, options); + + expect(withResults.length).toEqual(6); + + ctx.args.from = '2099/12/31'; + const noResults = await models.Client.transactions(ctx, filter, options); + + expect(noResults.length).toEqual(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/client/back/methods/client/transactions.js b/modules/client/back/methods/client/transactions.js index 6919107212..3ef61dd83d 100644 --- a/modules/client/back/methods/client/transactions.js +++ b/modules/client/back/methods/client/transactions.js @@ -28,6 +28,16 @@ module.exports = Self => { arg: 'amount', type: 'number', http: {source: 'query'} + }, + { + arg: 'from', + type: 'date', + http: {source: 'query'} + }, + { + arg: 'to', + type: 'date', + http: {source: 'query'} } ], returns: { @@ -47,6 +57,11 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); + if (ctx.args && args.to) { + const dateTo = args.to; + dateTo.setHours(23, 59, 0, 0); + } + const where = buildFilter(args, (param, value) => { switch (param) { case 'orderFk': @@ -55,6 +70,11 @@ module.exports = Self => { return {'t.clientFk': value}; case 'amount': return {'t.amount': (value * 100)}; + case 'from': + return {'t.created': {gte: value}}; + + case 'to': + return {'t.created': {lte: value}}; } }); From a7128b8187d1c8d5c006dfe25de6398342ea882c Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 2 Oct 2023 09:04:43 +0200 Subject: [PATCH 2/5] ref #5417 fix transactions --- modules/client/back/methods/client/transactions.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/transactions.js b/modules/client/back/methods/client/transactions.js index 3ef61dd83d..174ca4c4ea 100644 --- a/modules/client/back/methods/client/transactions.js +++ b/modules/client/back/methods/client/transactions.js @@ -59,7 +59,7 @@ module.exports = Self => { if (ctx.args && args.to) { const dateTo = args.to; - dateTo.setHours(23, 59, 0, 0); + dateTo.setHours(23, 59, 59, 999); } const where = buildFilter(args, (param, value) => { @@ -72,7 +72,6 @@ module.exports = Self => { return {'t.amount': (value * 100)}; case 'from': return {'t.created': {gte: value}}; - case 'to': return {'t.created': {lte: value}}; } From c59b119a4a2b04b2a0e37ef996802e5a9bdad08b Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 2 Oct 2023 10:06:04 +0200 Subject: [PATCH 3/5] ref #5417 fix transactions --- modules/client/back/methods/client/transactions.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/client/back/methods/client/transactions.js b/modules/client/back/methods/client/transactions.js index 174ca4c4ea..d08df4ab60 100644 --- a/modules/client/back/methods/client/transactions.js +++ b/modules/client/back/methods/client/transactions.js @@ -32,12 +32,10 @@ module.exports = Self => { { arg: 'from', type: 'date', - http: {source: 'query'} }, { arg: 'to', type: 'date', - http: {source: 'query'} } ], returns: { From 251d71a437e37f32380e56f12573b191012ed728 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Oct 2023 12:05:33 +0200 Subject: [PATCH 4/5] ref #5417 refactor transactions --- modules/client/back/methods/client/transactions.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/modules/client/back/methods/client/transactions.js b/modules/client/back/methods/client/transactions.js index d08df4ab60..a643d69f4d 100644 --- a/modules/client/back/methods/client/transactions.js +++ b/modules/client/back/methods/client/transactions.js @@ -12,22 +12,18 @@ module.exports = Self => { arg: 'filter', type: 'object', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', - http: {source: 'query'} }, { arg: 'orderFk', type: 'number', - http: {source: 'query'} }, { arg: 'clientFk', type: 'number', - http: {source: 'query'} }, { arg: 'amount', type: 'number', - http: {source: 'query'} }, { arg: 'from', @@ -48,19 +44,15 @@ module.exports = Self => { } }); - Self.transactions = async(ctx, filter, options) => { - const args = ctx.args; + Self.transactions = async(ctx, filter, orderFk, clientFk, amount, from, to, options) => { const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - if (ctx.args && args.to) { - const dateTo = args.to; - dateTo.setHours(23, 59, 59, 999); - } + if (to) to.setHours(23, 59, 59, 999); - const where = buildFilter(args, (param, value) => { + const where = buildFilter({orderFk, clientFk, amount, from, to}, (param, value) => { switch (param) { case 'orderFk': return {'t.id': value}; From 330fb08aac7ca8578bcdcd86e41930f911701f01 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Oct 2023 13:23:00 +0200 Subject: [PATCH 5/5] ref #5417 fix back test --- .../methods/client/specs/transactions.spec.js | 64 +++++++++++++++---- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/modules/client/back/methods/client/specs/transactions.spec.js b/modules/client/back/methods/client/specs/transactions.spec.js index 679eb196cc..54e0889293 100644 --- a/modules/client/back/methods/client/specs/transactions.spec.js +++ b/modules/client/back/methods/client/specs/transactions.spec.js @@ -1,15 +1,24 @@ const models = require('vn-loopback/server/server').models; describe('Client transactions', () => { + const ctx = {}; + it('should call transactions() method to receive a list of Web Payments from BRUCE WAYNE', async() => { const tx = await models.Client.beginTransaction({}); - try { const options = {transaction: tx}; - const ctx = {}; const filter = {where: {clientFk: 1101}}; - const result = await models.Client.transactions(ctx, filter, options); + const result = await models.Client.transactions( + ctx, + filter, + undefined, + undefined, + undefined, + undefined, + undefined, + options + ); expect(result[1].id).toBeTruthy(); @@ -26,9 +35,17 @@ describe('Client transactions', () => { try { const options = {transaction: tx}; - const ctx = {args: {orderFk: 6}}; const filter = {}; - const result = await models.Client.transactions(ctx, filter, options); + const result = await models.Client.transactions( + ctx, + filter, + 6, + undefined, + undefined, + undefined, + undefined, + options + ); const firstRow = result[0]; @@ -47,10 +64,17 @@ describe('Client transactions', () => { try { const options = {transaction: tx}; - - const ctx = {args: {amount: 40}}; const filter = {}; - const result = await models.Client.transactions(ctx, filter, options); + const result = await models.Client.transactions( + ctx, + filter, + undefined, + undefined, + 40, + undefined, + undefined, + options + ); const randomIndex = Math.floor(Math.random() * result.length); const transaction = result[randomIndex]; @@ -69,14 +93,30 @@ describe('Client transactions', () => { try { const options = {transaction: tx}; - const ctx = {args: {from: '2000/12/31'}}; const filter = {}; - const withResults = await models.Client.transactions(ctx, filter, options); + const withResults = await models.Client.transactions( + ctx, + filter, + undefined, + undefined, + undefined, + '2000/12/31', + undefined, + options + ); expect(withResults.length).toEqual(6); - ctx.args.from = '2099/12/31'; - const noResults = await models.Client.transactions(ctx, filter, options); + const noResults = await models.Client.transactions( + ctx, + filter, + undefined, + undefined, + undefined, + '2099/12/31', + undefined, + options + ); expect(noResults.length).toEqual(0);