Merge pull request '2878 - Splitted method into activeWithRole and activeWithInheritedRole' (#600) from 2878-activeWorkers_refactor into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #600
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2021-04-14 08:17:18 +00:00
commit 7e6b7ec491
31 changed files with 161 additions and 94 deletions

View File

@ -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();

View File

@ -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() => {

View File

@ -28,10 +28,10 @@
<vn-autocomplete
disabled="false"
ng-model="$ctrl.claim.workerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRole"
show-field="nickname"
search-function="{firstName: $search}"
where="{role: 'employee'}"
where="{role: 'salesPerson'}"
label="Attended by">
</vn-autocomplete>
<vn-autocomplete

View File

@ -68,7 +68,7 @@
</vn-autocomplete>
<vn-autocomplete
ng-model="claimDevelopment.workerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
show-field="nickname"
search-function="{firstName: $search}"
value-field="id"

View File

@ -25,20 +25,20 @@
<vn-autocomplete
vn-one
ng-model="filter.salesPersonFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRole"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'employee'}"
where="{role: 'salesPerson'}"
label="Salesperson">
<tpl-item>{{firstName}} {{name}}</tpl-item>
</vn-autocomplete>
<vn-autocomplete
vn-one
ng-model="filter.attenderFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRole"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'employee'}"
where="{role: 'salesPerson'}"
label="Attended by">
<tpl-item>{{firstName}} {{name}}</tpl-item>
</vn-autocomplete>

View File

@ -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();
});
});

View File

@ -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);

View File

@ -54,11 +54,11 @@
<vn-autocomplete
vn-one
ng-model="$ctrl.client.salesPersonFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
show-field="nickname"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'employee'}"
where="{role: 'salesPerson'}"
label="Salesperson"
vn-acl="salesAssistant">
</vn-autocomplete>

View File

@ -17,10 +17,10 @@
<vn-autocomplete
vn-one
ng-model="filter.buyerId"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRole"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'employee'}"
where="{role: 'buyer'}"
label="Buyer">
<tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete>

View File

@ -18,10 +18,10 @@
<vn-autocomplete
label="Salesperson"
ng-model="$ctrl.client.salesPersonFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
search-function="{firstName: $search}"
show-field="firstName"
where="{role: 'employee'}">
where="{role: 'salesPerson'}">
<tpl-item>{{firstName}} {{lastName}}</tpl-item>
</vn-autocomplete>
</vn-horizontal>

View File

@ -17,7 +17,7 @@
<vn-autocomplete
vn-one
ng-model="filter.salesPersonFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
search-function="{firstName: $search}"
show-field="firstName"
value-field="id"

View File

@ -39,11 +39,11 @@
<vn-autocomplete
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">
</vn-autocomplete>
</vn-horizontal>

View File

@ -44,7 +44,7 @@
<vn-autocomplete
vn-one
ng-model="filter.buyerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRolee"
show-field="nickname"
search-function="{firstName: $search}"
value-field="id"

View File

@ -17,10 +17,10 @@
<vn-autocomplete
vn-one
ng-model="filter.attenderFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRole"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'employee'}"
where="{role: 'buyer'}"
label="Atender">
<tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete>

View File

@ -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">
</vn-autocomplete>
</vn-horizontal>

View File

@ -28,11 +28,11 @@
<vn-autocomplete
vn-one
ng-model="filter.workerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
search-function="{firstName: $search}"
show-field="nickname"
value-field="id"
where="{role: 'employee'}"
where="{role: 'salesPerson'}"
label="Sales person">
</vn-autocomplete>
</vn-horizontal>

View File

@ -11,7 +11,7 @@
<vn-autocomplete
vn-one
ng-model="$ctrl.route.workerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
show-field="nickname"
search-function="{firstName: $search}"
value-field="id"

View File

@ -11,7 +11,7 @@
<vn-autocomplete
label="Worker"
ng-model="$ctrl.route.workerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
show-field="nickname"
search-function="{firstName: $search}"
where="{role: 'employee'}">

View File

@ -13,7 +13,7 @@
<vn-autocomplete
vn-one
ng-model="filter.workerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
show-field="nickname"
search-function="{firstName: $search}"
value-field="id"

View File

@ -18,7 +18,7 @@
<vn-autocomplete
vn-one
ng-model="$ctrl.supplier.workerFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
search-function="{firstName: $search}"
show-field="nickname"
value-field="id"

View File

@ -17,10 +17,10 @@
<vn-autocomplete
vn-one
ng-model="filter.buyerId"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRole"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'employee'}"
where="{role: 'buyer'}"
label="Buyer">
<tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete>

View File

@ -18,7 +18,7 @@
<vn-autocomplete
label="Buyer"
ng-model="$ctrl.ticketRequest.attenderFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithRole"
show-field="nickname"
where="{role: 'buyer'}"
search-function="{firstName: $search}">

View File

@ -60,7 +60,7 @@
<vn-autocomplete
vn-one
ng-model="filter.salesPersonFk"
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'employee'}"

View File

@ -21,7 +21,7 @@
</vn-autocomplete>
<vn-autocomplete
vn-one
url="Clients/activeWorkersWithRole"
url="Workers/activeWithInheritedRole"
ng-if="$ctrl.isPickerDesignedState"
ng-model="$ctrl.workerFk"
show-field="nickname"

View File

@ -3,26 +3,7 @@ const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
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);
};
};

View File

@ -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);
};
};

View File

@ -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);
};
};

View File

@ -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);
});
});

View File

@ -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');
});
});

View File

@ -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);
};

View File

@ -30,13 +30,13 @@
rule>
</vn-textfield>
<vn-autocomplete
disabled="false"
ng-model="$ctrl.worker.bossFk"
url="Clients/activeWorkersWithRole"
show-field="nickname"
search-function="{firstName: $search}"
where="{role: 'employee'}"
label="Boss">
disabled="false"
ng-model="$ctrl.worker.bossFk"
url="Clients/activeWorkersWithInheritRole"
show-field="nickname"
search-function="{firstName: $search}"
where="{role: 'employee'}"
label="Boss">
</vn-autocomplete>
</vn-horizontal>
</vn-vertical>