From b5a73ec3a200130eb35ac4404ff51b5423f749be Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 4 May 2022 10:32:14 +0200 Subject: [PATCH 1/6] 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) { -- 2.40.1 From ac4d4e6db10952ce85580b451606b5d7bd8edfc0 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 4 May 2022 10:59:37 +0200 Subject: [PATCH 2/6] test and fixtures --- db/dump/fixtures.sql | 80 ++++++++++--------- .../methods/sales-monitor/clientsFilter.js | 1 + .../sales-monitor/specs/clientsFilter.spec.js | 41 +++++++++- 3 files changed, 84 insertions(+), 38 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 0849e6708..da2b12588 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1640,51 +1640,59 @@ INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`) INSERT INTO `hedera`.`visit`(`id`, `firstAgentFk`) VALUES - (1, NULL), - (2, NULL), - (3, NULL), - (4, NULL), - (5, NULL), - (6, NULL), - (7, NULL), - (8, NULL), - (9, NULL); + (1, NULL), + (2, NULL), + (3, NULL), + (4, NULL), + (5, NULL), + (6, NULL), + (7, NULL), + (8, NULL), + (9, NULL), + (10, NULL), + (11, NULL); INSERT INTO `hedera`.`visitAgent`(`id`, `visitFk`) VALUES - (1, 1), - (2, 2), - (3, 3), - (4, 4), - (5, 5), - (6, 6), - (7, 7), - (8, 8), - (9, 9); + (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, 5), + (6, 6), + (7, 7), + (8, 8), + (9, 9), + (10, 10), + (11, 11); INSERT INTO `hedera`.`visitAccess`(`id`, `agentFk`, `stamp`) VALUES - (1, 1, CURDATE()), - (2, 2, CURDATE()), - (3, 3, CURDATE()), - (4, 4, CURDATE()), - (5, 5, CURDATE()), - (6, 6, CURDATE()), - (7, 7, CURDATE()), - (8, 8, CURDATE()), - (9, 9, CURDATE()); + (1, 1, CURDATE()), + (2, 2, CURDATE()), + (3, 3, CURDATE()), + (4, 4, CURDATE()), + (5, 5, CURDATE()), + (6, 6, CURDATE()), + (7, 7, CURDATE()), + (8, 8, CURDATE()), + (9, 9, CURDATE()), + (10, 10, CURDATE()), + (11, 11, CURDATE()); INSERT INTO `hedera`.`visitUser`(`id`, `accessFk`, `userFk`, `stamp`) VALUES - (1, 1, 1101, CURDATE()), - (2, 2, 1101, CURDATE()), - (3, 3, 1101, CURDATE()), - (4, 4, 1102, CURDATE()), - (5, 5, 1102, CURDATE()), - (6, 6, 1102, CURDATE()), - (7, 7, 1103, CURDATE()), - (8, 8, 1103, CURDATE()), - (9, 9, 1103, CURDATE()); + (1, 1, 1101, CURDATE()), + (2, 2, 1101, CURDATE()), + (3, 3, 1101, CURDATE()), + (4, 4, 1102, CURDATE()), + (5, 5, 1102, CURDATE()), + (6, 6, 1102, CURDATE()), + (7, 7, 1103, CURDATE()), + (8, 8, 1103, CURDATE()), + (9, 9, 1103, CURDATE()), + (10, 10, 1102, DATE_SUB(CURDATE(), INTERVAL 1 DAY)), + (11, 11, 1103, DATE_SUB(CURDATE(), INTERVAL 1 DAY)); INSERT INTO `hedera`.`userSession`(`created`, `lastUpdate`, `ssid`, `data`, `userVisitFk`) VALUES diff --git a/modules/monitor/back/methods/sales-monitor/clientsFilter.js b/modules/monitor/back/methods/sales-monitor/clientsFilter.js index daddf04fc..a08125551 100644 --- a/modules/monitor/back/methods/sales-monitor/clientsFilter.js +++ b/modules/monitor/back/methods/sales-monitor/clientsFilter.js @@ -45,6 +45,7 @@ module.exports = Self => { wtc.workerFk FROM hedera.visitUser v JOIN client c ON c.id = v.userFk + JOIN account.user u ON c.salesPersonFk = u.id LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk AND CURDATE() BETWEEN sc.started AND sc.ended LEFT JOIN workerTeamCollegues wtc 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 e7510e848..bcb37830c 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js @@ -6,9 +6,18 @@ describe('SalesMonitor clientsFilter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 18}}, args: {}}; - const filter = {order: 'dated DESC'}; + + const from = new Date(); + const to = new Date(); + from.setHours(0, 0, 0, 0); + to.setHours(23, 59, 59, 59); + + const filter = { + where: { + 'v.stamp': {between: [from, to]} + } + }; const result = await models.SalesMonitor.clientsFilter(ctx, filter, options); expect(result.length).toEqual(3); @@ -19,4 +28,32 @@ describe('SalesMonitor clientsFilter()', () => { throw e; } }); + + it('should return the clients web activity filtered', async() => { + const tx = await models.SalesMonitor.beginTransaction({}); + + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 18}}, args: {}}; + const yesterday = new Date(); + yesterday.setDate(yesterday.getDate() - 1); + const today = new Date(); + yesterday.setHours(0, 0, 0, 0); + today.setHours(23, 59, 59, 59); + + const filter = { + where: { + 'v.stamp': {between: [yesterday, today]} + } + }; + const result = await models.SalesMonitor.clientsFilter(ctx, filter, options); + + expect(result.length).toEqual(5); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); -- 2.40.1 From 70aca5d11adfe7c3e54c9cb14e518b0e2a4a975a Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 5 May 2022 13:25:57 +0200 Subject: [PATCH 3/6] fix(worker): fix getMonth --- modules/worker/back/methods/worker/createAbsence.js | 3 ++- modules/worker/back/methods/worker/deleteAbsence.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 44bda5627..fbbd97762 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -135,7 +135,8 @@ module.exports = Self => { function formatDate(date) { let day = date.getDate(); if (day < 10) day = `0${day}`; - let month = date.getMonth(); + let month = date.getMonth() + 1; + console.log(month); if (month < 10) month = `0${month}`; let year = date.getFullYear(); diff --git a/modules/worker/back/methods/worker/deleteAbsence.js b/modules/worker/back/methods/worker/deleteAbsence.js index 72e9243d9..45dc04b2d 100644 --- a/modules/worker/back/methods/worker/deleteAbsence.js +++ b/modules/worker/back/methods/worker/deleteAbsence.js @@ -87,7 +87,7 @@ module.exports = Self => { function formatDate(date) { let day = date.getDate(); if (day < 10) day = `0${day}`; - let month = date.getMonth(); + let month = date.getMonth() + 1; if (month < 10) month = `0${month}`; let year = date.getFullYear(); -- 2.40.1 From 1e3b05a95dfaba4668899c7f4fb5c13f012e4ece Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 5 May 2022 13:32:34 +0200 Subject: [PATCH 4/6] remove console.log --- modules/worker/back/methods/worker/createAbsence.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index fbbd97762..957bcc15f 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -136,7 +136,6 @@ module.exports = Self => { let day = date.getDate(); if (day < 10) day = `0${day}`; let month = date.getMonth() + 1; - console.log(month); if (month < 10) month = `0${month}`; let year = date.getFullYear(); -- 2.40.1 From 798147ea99731408f0bdd16ffa2d252e876c4166 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 5 May 2022 14:40:13 +0200 Subject: [PATCH 5/6] jenkins error --- modules/worker/back/methods/worker/createAbsence.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 957bcc15f..82cb5038e 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -135,6 +135,7 @@ module.exports = Self => { function formatDate(date) { let day = date.getDate(); if (day < 10) day = `0${day}`; + let month = date.getMonth() + 1; if (month < 10) month = `0${month}`; let year = date.getFullYear(); -- 2.40.1 From d34a8629f74e54760cdeae95ba1bd11139547b44 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 6 May 2022 13:09:37 +0200 Subject: [PATCH 6/6] fix(setSaleQuantity): save originalQuantity --- back/methods/collection/setSaleQuantity.js | 12 +++++++----- .../methods/collection/spec/setSaleQuantity.spec.js | 11 ++--------- modules/ticket/back/models/sale.json | 13 ++++++++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/back/methods/collection/setSaleQuantity.js b/back/methods/collection/setSaleQuantity.js index 82451b8be..644c44a60 100644 --- a/back/methods/collection/setSaleQuantity.js +++ b/back/methods/collection/setSaleQuantity.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('setSaleQuantity', { + Self.remoteMethod('setSaleQuantity', { description: 'Update sale quantity', accessType: 'WRITE', accepts: [{ @@ -24,11 +24,13 @@ module.exports = Self => { } }); - Self.setSaleQuantity = async ctx => { - const args = ctx.args; + Self.setSaleQuantity = async(saleId, quantity) => { const models = Self.app.models; - const sale = await models.Sale.findById(args.saleId,); - return await sale.updateAttribute('quantity', args.quantity); + const sale = await models.Sale.findById(saleId); + return await sale.updateAttributes({ + originalQuantity: sale.quantity, + quantity: quantity + }); }; }; diff --git a/back/methods/collection/spec/setSaleQuantity.spec.js b/back/methods/collection/spec/setSaleQuantity.spec.js index 4e3c8c4aa..5d06a4383 100644 --- a/back/methods/collection/spec/setSaleQuantity.spec.js +++ b/back/methods/collection/spec/setSaleQuantity.spec.js @@ -5,19 +5,12 @@ describe('setSaleQuantity()', () => { const saleId = 30; const newQuantity = 10; - const ctx = { - args: { - saleId: saleId, - quantity: newQuantity - } - }; - const originalSale = await models.Sale.findById(saleId); - await models.Collection.setSaleQuantity(ctx); + await models.Collection.setSaleQuantity(saleId, newQuantity); const updateSale = await models.Sale.findById(saleId); - expect(updateSale.quantity).toBeLessThan(originalSale.quantity); + expect(updateSale.originalQuantity).toEqual(originalSale.quantity); expect(updateSale.quantity).toEqual(newQuantity); }); }); diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 767a3e59e..14a6bc2cf 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -14,7 +14,7 @@ "properties": { "id": { "id": true, - "type": "Number", + "type": "number", "description": "Identifier" }, "concept": { @@ -22,22 +22,25 @@ "required": true }, "quantity": { - "type": "Number" + "type": "number" }, "price": { - "type": "Number" + "type": "number" }, "discount": { - "type": "Number" + "type": "number" }, "reserved": { "type": "boolean" }, "isPicked": { - "type": "Number" + "type": "number" }, "created": { "type": "date" + }, + "originalQuantity":{ + "type": "number" } }, "relations": { -- 2.40.1