This commit is contained in:
Carlos Jimenez Ruiz 2019-04-17 07:16:13 +02:00
commit 1f5fe891e4
9 changed files with 46 additions and 13 deletions

View File

@ -1260,7 +1260,7 @@ INSERT INTO `pbx`.`sip`(`user_id`, `extension`, `secret`, `caller_id`)
(9, 1201, '123456', 'developer');
INSERT INTO `postgresql`.`person`(`person_id`, `name`, `nickname`, `nif`, `firstname`, `id_trabajador`)
SELECT w.id, w.name, u.nickname,CONCAT(RPAD(CONCAT(w.id,9),8,w.id),'A'),w.firstName,w.id
SELECT w.id, w.lastName, u.nickname,CONCAT(RPAD(CONCAT(w.id,9),8,w.id),'A'),w.firstName,w.id
FROM `vn`.`worker` `w`
JOIN `account`.`user` `u` ON `u`.`id` = `w`.`userFk`;

View File

@ -16,14 +16,14 @@ module.exports = function(Self) {
Self.listWorkers = function() {
let query =
`SELECT w.id,
CONCAT(w.firstName, IFNULL(CONCAT(" ", w.name), "")) \`name\`
CONCAT(w.firstName, IFNULL(CONCAT(" ", w.lastName), "")) \`name\`
FROM worker w
JOIN account.user u ON w.userFk = u.id
JOIN account.roleRole rr ON rr.role = u.role
JOIN account.role r ON r.id = rr.inheritsFrom
WHERE u.active
AND r.\`name\` = 'employee'
ORDER BY w.name ASC`;
ORDER BY w.lastName ASC`;
return Self.rawSql(query);
};

View File

@ -106,7 +106,7 @@ module.exports = Self => {
i.value8,
tci.price,
tci.available,
w.name AS lastName,
w.lastName AS lastName,
w.firstName
FROM tmp.ticketCalculateItem tci
JOIN vn.item i ON i.id = tci.itemFk

View File

@ -187,7 +187,7 @@ module.exports = Self => {
w.name AS warehouse,
am.name AS agencyMode,
st.name AS state,
wk.name AS salesPerson,
wk.lastName AS salesPerson,
ts.stateFk as stateFk,
ts.alertLevel as alertLevel,
ts.code as alertLevelCode,

View File

@ -28,6 +28,11 @@ module.exports = Self => {
type: 'Integer',
description: 'The worker id',
http: {source: 'query'}
}, {
arg: 'userFk',
type: 'Integer',
description: 'The user id',
http: {source: 'query'}
}, {
arg: 'fi',
type: 'String',
@ -56,7 +61,7 @@ module.exports = Self => {
}, {
arg: 'nickname',
type: 'String',
description: 'The worker name',
description: 'The worker nickname',
http: {source: 'query'}
}
],
@ -80,13 +85,16 @@ module.exports = Self => {
? {'w.id': value}
: {or: [
{'w.firstName': {like: `%${value}%`}},
{'w.name': {like: `%${value}%`}},
{'u.name': {like: `%${value}%`}}
{'w.lastName': {like: `%${value}%`}},
{'u.name': {like: `%${value}%`}},
{'u.nickname': {like: `%${value}%`}}
]};
case 'id':
return {'w.id': value};
case 'userFk':
return {'w.userFk': value};
case 'name':
return {'w.name': {like: `%${value}%`}};
return {'w.lastName': {like: `%${value}%`}};
case 'firstName':
return {'w.firstName': {like: `%${value}%`}};
case 'extension':
@ -107,7 +115,7 @@ module.exports = Self => {
stmt = new ParameterizedSQL(
`SELECT w.id, u.email, p.extension, u.name as userName,
d.name AS department, w.name, u.nickname, mu.email
d.name AS department, w.lastName, u.nickname, mu.email
FROM worker w
LEFT JOIN workerDepartment wd ON wd.workerFk = w.id
LEFT JOIN department d ON d.id = wd.departmentFk

View File

@ -0,0 +1,25 @@
const app = require('vn-loopback/server/server');
describe('worker filter()', () => {
it('should return 1 result filtering by id', async() => {
let result = await app.models.Worker.filter({args: {filter: {}, search: 1}});
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1);
});
it('should return 1 result filtering by string', async() => {
let result = await app.models.Worker.filter({args: {filter: {}, search: 'administrativeNick'}});
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(5);
});
it('should return 2 results filtering by name', async() => {
let result = await app.models.Worker.filter({args: {filter: {}, name: 'agency'}});
expect(result.length).toEqual(2);
expect(result[0].nickname).toEqual('agencyNick');
expect(result[1].nickname).toEqual('agencyBossNick');
});
});

View File

@ -18,7 +18,7 @@
<vn-textfield
vn-one
label="User id"
model="filter.id">
model="filter.userFk">
</vn-textfield>
</vn-horizontal>
<vn-horizontal>

View File

@ -30,7 +30,7 @@ module.exports = {
u.lang locale,
u.name AS userName,
c.email recipient,
CONCAT(w.name, ' ', w.firstName) salesPersonName,
CONCAT(w.lastName, ' ', w.firstName) salesPersonName,
w.phone AS salesPersonPhone,
CONCAT(wu.name, '@verdnatura.es') AS salesPersonEmail
FROM client c

View File

@ -38,7 +38,7 @@ module.exports = {
u.lang locale,
u.name AS userName,
c.email recipient,
CONCAT(w.name, ' ', w.firstName) salesPersonName,
CONCAT(w.lastName, ' ', w.firstName) salesPersonName,
w.phone AS salesPersonPhone,
CONCAT(wu.name, '@verdnatura.es') AS salesPersonEmail
FROM client c