From 6b8074e32f80a5e84382d5cb77c449ef7d4e7d9e Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 13 Apr 2021 14:08:10 +0200 Subject: [PATCH 1/3] 2878 - Splitted method into activeWithRole and activeWithInheritedRole --- modules/claim/front/basic-data/index.html | 4 +-- modules/claim/front/development/index.html | 2 +- modules/claim/front/search-panel/index.html | 8 ++--- modules/client/back/models/client.js | 1 - modules/client/front/basic-data/index.html | 4 +-- .../front/consumption-search-panel/index.html | 4 +-- modules/client/front/create/index.html | 4 +-- modules/client/front/search-panel/index.html | 2 +- .../front/latest-buys-search-panel/index.html | 4 +-- .../front/fixed-price-search-panel/index.html | 2 +- .../front/request-search-panel/index.html | 4 +-- modules/item/front/search-panel/index.html | 4 +-- modules/order/front/search-panel/index.html | 4 +-- modules/route/front/basic-data/index.html | 2 +- modules/route/front/create/index.html | 2 +- modules/route/front/search-panel/index.html | 2 +- modules/supplier/front/basic-data/index.html | 2 +- .../front/consumption-search-panel/index.html | 4 +-- .../ticket/front/request/create/index.html | 2 +- modules/ticket/front/search-panel/index.html | 2 +- modules/ticket/front/tracking/edit/index.html | 2 +- .../back/methods/worker/active.js} | 31 ++---------------- .../methods/worker/activeWithInheritedRole.js | 32 +++++++++++++++++++ .../back/methods/worker/activeWithRole.js | 31 ++++++++++++++++++ modules/worker/back/models/worker.js | 3 ++ modules/worker/front/basic-data/index.html | 14 ++++---- 26 files changed, 108 insertions(+), 68 deletions(-) rename modules/{client/back/methods/client/activeWorkersWithRole.js => worker/back/methods/worker/active.js} (59%) create mode 100644 modules/worker/back/methods/worker/activeWithInheritedRole.js create mode 100644 modules/worker/back/methods/worker/activeWithRole.js diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index 064a9d4f5..a39ecc56e 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -28,10 +28,10 @@ {{firstName}} {{name}} {{firstName}} {{name}} diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 035074210..842565c3f 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -8,7 +8,6 @@ const LoopBackContext = require('loopback-context'); module.exports = Self => { // Methods - require('../methods/client/activeWorkersWithRole')(Self); require('../methods/client/getCard')(Self); require('../methods/client/createWithUser')(Self); require('../methods/client/listWorkers')(Self); diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index 6235ec923..e4debac16 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -54,11 +54,11 @@ diff --git a/modules/client/front/consumption-search-panel/index.html b/modules/client/front/consumption-search-panel/index.html index fbcf24fad..28370537d 100644 --- a/modules/client/front/consumption-search-panel/index.html +++ b/modules/client/front/consumption-search-panel/index.html @@ -17,10 +17,10 @@ {{nickname}} diff --git a/modules/client/front/create/index.html b/modules/client/front/create/index.html index d9759e347..c5fa35658 100644 --- a/modules/client/front/create/index.html +++ b/modules/client/front/create/index.html @@ -18,10 +18,10 @@ + where="{role: 'salesPerson'}"> {{firstName}} {{lastName}} diff --git a/modules/client/front/search-panel/index.html b/modules/client/front/search-panel/index.html index 757767671..9caf4185b 100644 --- a/modules/client/front/search-panel/index.html +++ b/modules/client/front/search-panel/index.html @@ -17,7 +17,7 @@ diff --git a/modules/item/front/fixed-price-search-panel/index.html b/modules/item/front/fixed-price-search-panel/index.html index 5a1e7781e..773862bf1 100644 --- a/modules/item/front/fixed-price-search-panel/index.html +++ b/modules/item/front/fixed-price-search-panel/index.html @@ -44,7 +44,7 @@ {{nickname}} diff --git a/modules/item/front/search-panel/index.html b/modules/item/front/search-panel/index.html index f30442ec6..545cffda0 100644 --- a/modules/item/front/search-panel/index.html +++ b/modules/item/front/search-panel/index.html @@ -42,11 +42,11 @@ vn-one disabled="false" ng-model="filter.salesPersonFk" - url="Clients/activeWorkersWithRole" + url="Workers/activeWithRole" show-field="nickname" search-function="{firstName: $search}" value-field="id" - where="{role: 'employee'}" + where="{role: 'buyer'}" label="Buyer"> diff --git a/modules/order/front/search-panel/index.html b/modules/order/front/search-panel/index.html index f9b214578..c622dd152 100644 --- a/modules/order/front/search-panel/index.html +++ b/modules/order/front/search-panel/index.html @@ -28,11 +28,11 @@ diff --git a/modules/route/front/basic-data/index.html b/modules/route/front/basic-data/index.html index 0a1734ff2..d3ba25b11 100644 --- a/modules/route/front/basic-data/index.html +++ b/modules/route/front/basic-data/index.html @@ -11,7 +11,7 @@ diff --git a/modules/route/front/search-panel/index.html b/modules/route/front/search-panel/index.html index 4c9dd3110..6e3d30d30 100644 --- a/modules/route/front/search-panel/index.html +++ b/modules/route/front/search-panel/index.html @@ -13,7 +13,7 @@ {{nickname}} diff --git a/modules/ticket/front/request/create/index.html b/modules/ticket/front/request/create/index.html index 755e8cb51..f7280b2de 100644 --- a/modules/ticket/front/request/create/index.html +++ b/modules/ticket/front/request/create/index.html @@ -18,7 +18,7 @@ diff --git a/modules/ticket/front/search-panel/index.html b/modules/ticket/front/search-panel/index.html index 55611899b..d0b77b9de 100644 --- a/modules/ticket/front/search-panel/index.html +++ b/modules/ticket/front/search-panel/index.html @@ -60,7 +60,7 @@ { - Self.remoteMethod('activeWorkersWithRole', { - description: 'Returns actives workers with salesperson role', - accessType: 'READ', - accepts: [{ - arg: 'filter', - type: 'Object', - description: 'Filter defining where and paginated data', - required: true - }], - returns: { - type: 'Worker', - root: true - }, - http: { - path: `/activeWorkersWithRole`, - verb: 'get' - } - }); - - Self.activeWorkersWithRole = async filter => { + Self.activeWorkers = async(query, filter) => { let conn = Self.dataSource.connector; if (filter.where && filter.where.and && Array.isArray(filter.where.and)) { let where = {}; @@ -54,14 +35,8 @@ module.exports = Self => { myFilter = mergeFilters(myFilter, clientFilter); - let stmt = new ParameterizedSQL( - `SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname - FROM worker w - JOIN account.user u ON u.id = w.userFk - JOIN account.roleRole i ON i.role = u.role - JOIN account.role r ON r.id = i.inheritsFrom` - ); + let stmt = new ParameterizedSQL(query); stmt.merge(conn.makeSuffix(myFilter)); - return await conn.executeStmt(stmt); + return conn.executeStmt(stmt); }; }; diff --git a/modules/worker/back/methods/worker/activeWithInheritedRole.js b/modules/worker/back/methods/worker/activeWithInheritedRole.js new file mode 100644 index 000000000..9536b0f29 --- /dev/null +++ b/modules/worker/back/methods/worker/activeWithInheritedRole.js @@ -0,0 +1,32 @@ + +module.exports = Self => { + Self.remoteMethod('activeWithInheritedRole', { + description: 'Returns active workers with a role', + accessType: 'READ', + accepts: [{ + arg: 'filter', + type: 'Object', + description: 'Filter defining where and paginated data', + required: true + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/activeWithInheritedRole`, + verb: 'GET' + } + }); + + Self.activeWithInheritedRole = async filter => { + const query = + `SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname + FROM worker w + JOIN account.user u ON u.id = w.userFk + JOIN account.roleRole i ON i.role = u.role + JOIN account.role r ON r.id = i.inheritsFrom`; + + return Self.activeWorkers(query, filter); + }; +}; diff --git a/modules/worker/back/methods/worker/activeWithRole.js b/modules/worker/back/methods/worker/activeWithRole.js new file mode 100644 index 000000000..392416458 --- /dev/null +++ b/modules/worker/back/methods/worker/activeWithRole.js @@ -0,0 +1,31 @@ + +module.exports = Self => { + Self.remoteMethod('activeWithRole', { + description: 'Returns active workers with an inherited role', + accessType: 'READ', + accepts: [{ + arg: 'filter', + type: 'Object', + description: 'Filter defining where and paginated data', + required: true + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/activeWithRole`, + verb: 'GET' + } + }); + + Self.activeWithRole = async filter => { + const query = + `SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname + FROM worker w + JOIN account.user u ON u.id = w.id + JOIN account.role r ON r.id = u.role`; + + return Self.activeWorkers(query, filter); + }; +}; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 0d94c788e..9bfef5235 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -7,4 +7,7 @@ module.exports = Self => { require('../methods/worker/createAbsence')(Self); require('../methods/worker/deleteAbsence')(Self); require('../methods/worker/updateAbsence')(Self); + require('../methods/worker/active')(Self); + require('../methods/worker/activeWithRole')(Self); + require('../methods/worker/activeWithInheritedRole')(Self); }; diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index a767eccc4..228ae39d4 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -30,13 +30,13 @@ rule> + disabled="false" + ng-model="$ctrl.worker.bossFk" + url="Clients/activeWorkersWithInheritRole" + show-field="nickname" + search-function="{firstName: $search}" + where="{role: 'employee'}" + label="Boss"> From 78313bd9a7b32b9d9f45d2f07412983cc7d6a19c Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 14 Apr 2021 08:15:03 +0200 Subject: [PATCH 2/3] Updated unit tests --- .../specs/activeWorkersWithRole.spec.js | 23 --------------- .../specs/activeWithInheritedRole.spec.js | 29 +++++++++++++++++++ .../worker/specs/activeWithRole.spec.js | 21 ++++++++++++++ 3 files changed, 50 insertions(+), 23 deletions(-) delete mode 100644 modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js create mode 100644 modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js create mode 100644 modules/worker/back/methods/worker/specs/activeWithRole.spec.js diff --git a/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js b/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js deleted file mode 100644 index fcf871d9b..000000000 --- a/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js +++ /dev/null @@ -1,23 +0,0 @@ -const app = require('vn-loopback/server/server'); - -describe('Client activeWorkersWithRole', () => { - it('should return the sales people as result', async() => { - let filter = {where: {role: 'salesPerson'}}; - let result = await app.models.Client.activeWorkersWithRole(filter); - - let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson'); - - expect(result.length).toEqual(19); - expect(isSalesPerson).toBeTruthy(); - }); - - it('should return the buyers as result', async() => { - let filter = {where: {role: 'buyer'}}; - let result = await app.models.Client.activeWorkersWithRole(filter); - - let isBuyer = await app.models.Account.hasRole(result[0].id, 'buyer'); - - expect(result.length).toEqual(17); - expect(isBuyer).toBeTruthy(); - }); -}); diff --git a/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js new file mode 100644 index 000000000..c44fb72f9 --- /dev/null +++ b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js @@ -0,0 +1,29 @@ +const app = require('vn-loopback/server/server'); + +describe('Worker activeWithInheritedRole', () => { + it('should return the workers with an inherited role of salesPerson', async() => { + const filter = {where: {role: 'salesPerson'}}; + const result = await app.models.Worker.activeWithInheritedRole(filter); + + const randomIndex = Math.floor(Math.random() * result.length); + const worker = result[randomIndex]; + + const isSalesPerson = await app.models.Account.hasRole(worker.id, 'salesPerson'); + + expect(result.length).toEqual(19); + expect(isSalesPerson).toBe(true); + }); + + it('should return the workers with an inherited role of buyer', async() => { + const filter = {where: {role: 'buyer'}}; + const result = await app.models.Worker.activeWithInheritedRole(filter); + + const randomIndex = Math.floor(Math.random() * result.length); + const worker = result[randomIndex]; + + const isBuyer = await app.models.Account.hasRole(worker.id, 'buyer'); + + expect(result.length).toEqual(17); + expect(isBuyer).toBe(true); + }); +}); diff --git a/modules/worker/back/methods/worker/specs/activeWithRole.spec.js b/modules/worker/back/methods/worker/specs/activeWithRole.spec.js new file mode 100644 index 000000000..88a312e24 --- /dev/null +++ b/modules/worker/back/methods/worker/specs/activeWithRole.spec.js @@ -0,0 +1,21 @@ +const app = require('vn-loopback/server/server'); + +describe('Worker activeWithRole', () => { + it('should return the sales people as result', async() => { + const filter = {where: {role: 'salesPerson'}}; + const result = await app.models.Worker.activeWithRole(filter); + const firstWorker = result[0]; + + expect(result.length).toEqual(1); + expect(firstWorker.nickname).toEqual('salesPersonNick'); + }); + + it('should return the buyers as result', async() => { + const filter = {where: {role: 'buyer'}}; + const result = await app.models.Worker.activeWithRole(filter); + const firstWorker = result[0]; + + expect(result.length).toEqual(1); + expect(firstWorker.nickname).toEqual('buyerNick'); + }); +}); From 55b3a048e7bcc7cd3e61bdb3ddf308fb45371c18 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 14 Apr 2021 08:49:10 +0200 Subject: [PATCH 3/3] Updated E2E --- e2e/paths/02-client/01_create_client.spec.js | 2 +- e2e/paths/02-client/02_edit_basic_data.spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js index 4cb3c67ab..ae002b0ea 100644 --- a/e2e/paths/02-client/01_create_client.spec.js +++ b/e2e/paths/02-client/01_create_client.spec.js @@ -31,7 +31,7 @@ describe('Client create path', () => { await page.write(selectors.createClientView.taxNumber, '74451390E'); await page.write(selectors.createClientView.userName, 'CaptainMarvel'); await page.write(selectors.createClientView.email, 'CarolDanvers@verdnatura.es'); - await page.autocompleteSearch(selectors.createClientView.salesPerson, 'replenisher'); + await page.autocompleteSearch(selectors.createClientView.salesPerson, 'salesPerson'); await page.waitToClick(selectors.createClientView.createButton); const message = await page.waitForSnackbar(); diff --git a/e2e/paths/02-client/02_edit_basic_data.spec.js b/e2e/paths/02-client/02_edit_basic_data.spec.js index 6f331fb23..d770e7523 100644 --- a/e2e/paths/02-client/02_edit_basic_data.spec.js +++ b/e2e/paths/02-client/02_edit_basic_data.spec.js @@ -96,7 +96,7 @@ describe('Client Edit basicData path', () => { await page.write(selectors.clientBasicData.phone, '333333333'); await page.clearInput(selectors.clientBasicData.mobile); await page.write(selectors.clientBasicData.mobile, '444444444'); - await page.autocompleteSearch(selectors.clientBasicData.salesPerson, 'replenisherNick'); + await page.autocompleteSearch(selectors.clientBasicData.salesPerson, 'salesPerson'); await page.autocompleteSearch(selectors.clientBasicData.channel, 'Metropolis newspaper'); await page.waitToClick(selectors.clientBasicData.saveButton); const message = await page.waitForSnackbar(); @@ -143,7 +143,7 @@ describe('Client Edit basicData path', () => { const result = await page .waitToGetProperty(selectors.clientBasicData.salesPerson, 'value'); - expect(result).toEqual('replenisherNick'); + expect(result).toEqual('salesPersonNick'); }); it('should now confirm the channel have been selected', async() => {