#779 ticket.ticketRequester

This commit is contained in:
Carlos Jimenez 2018-11-12 11:17:47 +01:00
parent 25db73a88b
commit 247aa317af
9 changed files with 90 additions and 31 deletions

View File

@ -1,5 +1,6 @@
<div class="icon-menu"> <div class="icon-menu">
<vn-icon <vn-icon
pointer
class="button" class="button"
ng-click="$ctrl.onClick($event)" ng-click="$ctrl.onClick($event)"
vn-none vn-none

View File

@ -191,6 +191,12 @@
"state": "ticket.weekly", "state": "ticket.weekly",
"component": "vn-ticket-weekly", "component": "vn-ticket-weekly",
"description": "Weekly" "description": "Weekly"
},
{
"url" : "/request",
"state": "ticket.card.request",
"component": "vn-ticket-request",
"description": "Purchase request"
} }
], ],
"menu": [ "menu": [
@ -205,6 +211,7 @@
{"state": "ticket.card.components", "icon": "icon-components"}, {"state": "ticket.card.components", "icon": "icon-components"},
{"state": "ticket.card.saleTracking", "icon": "assignment"}, {"state": "ticket.card.saleTracking", "icon": "assignment"},
{"state": "ticket.card.picture", "icon": "image"}, {"state": "ticket.card.picture", "icon": "image"},
{"state": "ticket.card.log", "icon": "history"} {"state": "ticket.card.log", "icon": "history"},
{"state": "ticket.card.request", "icon": "info"}
] ]
} }

View File

@ -20,5 +20,6 @@ import './sale-checked';
import './component'; import './component';
import './sale-tracking'; import './sale-tracking';
import './picture'; import './picture';
import './request';
// import './log'; // import './log';
import './weekly'; import './weekly';

View File

@ -0,0 +1,48 @@
module.exports = Self => {
Self.remoteMethod('activeBuyer', {
description: 'Returns actives workers with Buyer role',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
required: false,
description: 'Filter defining where and paginated data',
http: {source: 'query'}
}],
returns: {
type: 'Worker',
root: true
},
http: {
path: `/activeBuyer`,
verb: 'get'
}
});
Self.activeBuyer = async filter => {
let sqlLimit = '';
let sqlOffset = '';
let params = [];
if (filter.limit) {
sqlLimit = `LIMIT ?`;
params.push(filter.limit);
}
if (filter.skip) {
sqlOffset = `OFFSET ?`;
params.push(filter.skip);
}
let query =
`SELECT worker.id, worker.firstName, worker.name
FROM vn.worker
JOIN account.user user ON user.id = worker.userFk
JOIN account.role role ON role.name = 'buyer'
JOIN account.roleRole inheritance ON inheritance.role = user.role AND inheritance.inheritsFrom = role.id
WHERE user.active IS TRUE
ORDER BY worker.firstName ASC
${sqlLimit} ${sqlOffset}`;
return await Self.rawSql(query, params);
};
};

View File

@ -20,24 +20,10 @@ module.exports = Self => {
}); });
Self.activeSalesPerson = async filter => { Self.activeSalesPerson = async filter => {
let where = filter.where;
let sqlWhere = '';
let sqlLimit = ''; let sqlLimit = '';
let sqlOffset = ''; let sqlOffset = '';
let params = []; let params = [];
if (where) {
if (where.firstName) {
sqlWhere = `AND (em.firstName LIKE ? OR em.name LIKE ?)`;
let search = where.firstName.like;
params.push(search);
params.push(search);
}
if (where.id) {
sqlWhere = `AND em.id = ?`;
params.push(where.id);
}
}
if (filter.limit) { if (filter.limit) {
sqlLimit = `LIMIT ?`; sqlLimit = `LIMIT ?`;
params.push(filter.limit); params.push(filter.limit);
@ -48,12 +34,13 @@ module.exports = Self => {
} }
let query = let query =
`SELECT em.id, em.firstName, em.name `SELECT worker.id, worker.firstName, worker.name
FROM worker em FROM vn.worker
JOIN account.user ac ON em.userFk = ac.id JOIN account.user user ON user.id = worker.userFk
JOIN account.role r ON r.id = ac.role JOIN account.role role ON role.name = 'salesPerson'
WHERE ac.active ${sqlWhere} JOIN account.roleRole inheritance ON inheritance.role = user.role AND inheritance.inheritsFrom = role.id
ORDER BY em.name ASC WHERE user.active IS TRUE
ORDER BY worker.firstName ASC
${sqlLimit} ${sqlOffset}`; ${sqlLimit} ${sqlOffset}`;
return await Self.rawSql(query, params); return await Self.rawSql(query, params);

View File

@ -0,0 +1,13 @@
const app = require(`${servicesDir}/client/server/server`);
describe('Client activeBuyer', () => {
it('should return the buyers as result', async () => {
let filter = {};
let result = await app.models.Client.activeBuyer(filter);
let isBuyer = await app.models.Account.hasRole(result[0].id, 'buyer');
expect(result.length).toEqual(9);
expect(isBuyer).toBeTruthy();
});
});

View File

@ -1,12 +1,13 @@
const app = require(`${servicesDir}/client/server/server`); const app = require(`${servicesDir}/client/server/server`);
describe('Client activeSalesPerson', () => { describe('Client activeSalesPerson', () => {
it('should call the activeSalesPerson() method with limit of 1', async() => { it('should return the sales people as result', async () => {
let filter = { let filter = {};
limit: 1
};
let result = await app.models.Client.activeSalesPerson(filter); let result = await app.models.Client.activeSalesPerson(filter);
expect(result.length).toEqual(1); let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson');
expect(result.length).toEqual(10);
expect(isSalesPerson).toBeTruthy();
}); });
}); });

View File

@ -8,9 +8,9 @@ module.exports = Self => {
}); });
Self.observe('before save', (ctx, next) => { Self.observe('before save', (ctx, next) => {
if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password) { if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password)
ctx.data.password = md5(ctx.data.password); ctx.data.password = md5(ctx.data.password);
}
next(); next();
}); });
@ -64,7 +64,7 @@ module.exports = Self => {
* @param {Integer} userId The user id * @param {Integer} userId The user id
* @return {Object} User role list * @return {Object} User role list
*/ */
Self.getRoles = async function(userId) { Self.getRoles = async userId => {
let result = await Self.rawSql( let result = await Self.rawSql(
`SELECT r.name `SELECT r.name
FROM account.user u FROM account.user u
@ -73,9 +73,9 @@ module.exports = Self => {
WHERE u.id = ?`, [userId]); WHERE u.id = ?`, [userId]);
let roles = []; let roles = [];
for (role of result) { for (role of result)
roles.push(role.name); roles.push(role.name);
}
return roles; return roles;
}; };

View File

@ -10,6 +10,7 @@ module.exports = Self => {
require('../methods/client/hasCustomerRole')(Self); require('../methods/client/hasCustomerRole')(Self);
require('../methods/client/isValidClient')(Self); require('../methods/client/isValidClient')(Self);
require('../methods/client/activeSalesPerson')(Self); require('../methods/client/activeSalesPerson')(Self);
require('../methods/client/activeBuyer')(Self);
require('../methods/client/addressesPropagateRe')(Self); require('../methods/client/addressesPropagateRe')(Self);
require('../methods/client/getDebt')(Self); require('../methods/client/getDebt')(Self);
require('../methods/client/getMana')(Self); require('../methods/client/getMana')(Self);