From d831b5197ddf131f31f1d9bbd21f5afe90440104 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 8 Jan 2025 12:30:15 +0100 Subject: [PATCH] feat: refs #8077 create testo to sumAmount --- modules/client/back/methods/defaulter/filter.js | 7 ++++--- .../back/methods/defaulter/specs/filter.spec.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index 14b55f9b9..c43e045fa 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -56,8 +56,7 @@ module.exports = Self => { filter = mergeFilters(ctx.args.filter, {where}); const stmts = []; - const fields = ctx.args.sumAmount ? 'sum(d.amount) sumAmount' : ` DISTINCT c.id clientFk, - c.name clientName, + const sqlCode = `, c.name clientName, c.salesPersonFk, c.businessTypeFk = 'worker' isWorker, u.name salesPersonName, @@ -75,6 +74,8 @@ module.exports = Self => { dp.id departmentFk, dp.name departmentName, dp.notificationEmail departmentEmail`; + const fields = ctx.args.sumAmount ? `sum(d.amount) sumAmount, d.clientFk ${sqlCode}` + : ` DISTINCT c.id clientFk ${sqlCode}`; const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const stmt = new ParameterizedSQL( @@ -108,7 +109,7 @@ module.exports = Self => { , [date]); stmt.merge(conn.makeWhere(filter.where)); - !ctx.args.sumAmount && stmt.merge(`GROUP BY d.clientFk`); + !ctx.args.sumAmount && stmt.merge(`GROUP BY clientFk`); stmt.merge(conn.makeOrderBy(filter.order)); stmt.merge(conn.makeLimit(filter)); diff --git a/modules/client/back/methods/defaulter/specs/filter.spec.js b/modules/client/back/methods/defaulter/specs/filter.spec.js index 0a970823e..b5f008b08 100644 --- a/modules/client/back/methods/defaulter/specs/filter.spec.js +++ b/modules/client/back/methods/defaulter/specs/filter.spec.js @@ -60,4 +60,21 @@ describe('defaulter filter()', () => { throw e; } }); + + it('should return the defaulter the sum of every defaulters', async() => { + const tx = await models.Defaulter.beginTransaction({}); + + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 1101, sumAmount: true}}; + const [result] = await models.Defaulter.filter(ctx, null, options); + + expect(result.sumAmount).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); });