From 6b8074e32f80a5e84382d5cb77c449ef7d4e7d9e Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 13 Apr 2021 14:08:10 +0200 Subject: [PATCH] 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">