diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js
index 4cb3c67abd..ae002b0ea4 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 6f331fb237..d770e7523f 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() => {
diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html
index 064a9d4f55..a39ecc56e1 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/methods/client/specs/activeWorkersWithRole.spec.js b/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js
deleted file mode 100644
index fcf871d9b0..0000000000
--- 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/client/back/models/client.js b/modules/client/back/models/client.js
index 035074210b..842565c3f1 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 6235ec9238..e4debac16e 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 fbcf24fade..28370537d7 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 d9759e3478..c5fa356587 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 7577676716..9caf4185bb 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 5a1e7781e3..773862bf17 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 f30442ec61..545cffda0d 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 f9b214578d..c622dd1523 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 0a1734ff2a..d3ba25b110 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 4c9dd3110f..6e3d30d306 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 755e8cb513..f7280b2de3 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 55611899b7..d0b77b9dea 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 0000000000..9536b0f29b
--- /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 0000000000..3924164585
--- /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/methods/worker/specs/activeWithInheritedRole.spec.js b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js
new file mode 100644
index 0000000000..c44fb72f97
--- /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 0000000000..88a312e24c
--- /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');
+ });
+});
diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js
index 0d94c788ec..9bfef52351 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 a767eccc4a..228ae39d41 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">