From b5a73ec3a200130eb35ac4404ff51b5423f749be Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 4 May 2022 10:32:14 +0200 Subject: [PATCH] fix(monitor_client): clientsFilter refactor --- .../monitor/back/methods/sales-monitor/clientsFilter.js | 9 ++++----- .../methods/sales-monitor/specs/clientsFilter.spec.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/monitor/back/methods/sales-monitor/clientsFilter.js b/modules/monitor/back/methods/sales-monitor/clientsFilter.js index 3d8edf608..daddf04fc 100644 --- a/modules/monitor/back/methods/sales-monitor/clientsFilter.js +++ b/modules/monitor/back/methods/sales-monitor/clientsFilter.js @@ -43,11 +43,8 @@ module.exports = Self => { TIME(v.stamp) AS hour, DATE(v.stamp) AS dated, wtc.workerFk - FROM hedera.userSession s - JOIN hedera.visitUser v ON v.id = s.userVisitFk + FROM hedera.visitUser v JOIN client c ON c.id = v.userFk - LEFT JOIN account.user u ON c.salesPersonFk = u.id - LEFT JOIN worker w ON c.salesPersonFk = w.id LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk AND CURDATE() BETWEEN sc.started AND sc.ended LEFT JOIN workerTeamCollegues wtc @@ -58,7 +55,9 @@ module.exports = Self => { const where = filter.where; where['wtc.workerFk'] = userId; - stmt.merge(conn.makeSuffix(filter)); + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(`GROUP BY clientFk, v.stamp`); + stmt.merge(conn.makePagination(filter)); return conn.executeStmt(stmt, myOptions); }; diff --git a/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js index 3fcc6c91a..e7510e848 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js @@ -11,7 +11,7 @@ describe('SalesMonitor clientsFilter()', () => { const filter = {order: 'dated DESC'}; const result = await models.SalesMonitor.clientsFilter(ctx, filter, options); - expect(result.length).toEqual(9); + expect(result.length).toEqual(3); await tx.rollback(); } catch (e) {