From 83b211e709ddec3f7a86c28e9ac0f64b05c50cf3 Mon Sep 17 00:00:00 2001
From: Carlos Jimenez <=>
Date: Tue, 13 Nov 2018 11:26:36 +0100
Subject: [PATCH] #779 ticket.ticketRequester
---
client/ticket/routes.json | 3 +-
client/ticket/src/request/index.html | 11 +-
client/ticket/src/request/locale/es.yml | 2 +
package-lock.json | 208 +++++++++---------
.../common/methods/client/activeBuyer.js | 22 +-
.../methods/client/activeSalesPerson.js | 22 +-
.../loopback/common/models/ticket-request.js | 13 ++
.../common/models/ticket-request.json | 10 +-
8 files changed, 171 insertions(+), 120 deletions(-)
create mode 100644 client/ticket/src/request/locale/es.yml
create mode 100644 services/loopback/common/models/ticket-request.js
diff --git a/client/ticket/routes.json b/client/ticket/routes.json
index 49f163087..7eeab37e2 100644
--- a/client/ticket/routes.json
+++ b/client/ticket/routes.json
@@ -196,7 +196,8 @@
"url" : "/request",
"state": "ticket.card.request",
"component": "vn-ticket-request",
- "description": "Purchase request"
+ "description": "Purchase request",
+ "acl": ["salesPerson"]
}
],
"menu": [
diff --git a/client/ticket/src/request/index.html b/client/ticket/src/request/index.html
index c3663d7e1..536e99100 100644
--- a/client/ticket/src/request/index.html
+++ b/client/ticket/src/request/index.html
@@ -18,22 +18,23 @@
vn-two
label="Description"
model="request.description"
- vn-acl="salesPerson">
+ rule="TicketRequest.description"
+ vn-focus>
+ show-field="name">
{{firstName}} {{name}}
{
});
Self.activeBuyer = async filter => {
+ let sqlWhere = '';
let sqlLimit = '';
let sqlOffset = '';
let params = [];
+ if (filter.where) {
+ if (filter.where.firstName) {
+ sqlWhere = `AND (worker.firstName LIKE ? OR worker.name LIKE ?)`;
+ let search = where.firstName.like;
+ params.push(search);
+ params.push(search);
+ }
+ if (filter.where.id) {
+ sqlWhere = `AND worker.id = ?`;
+ params.push(filter.where.id);
+ }
+ }
+
if (filter.limit) {
sqlLimit = `LIMIT ?`;
params.push(filter.limit);
@@ -37,10 +51,10 @@ module.exports = Self => {
`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
+ 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 ${sqlWhere}
+ ORDER BY worker.firstName ASC
${sqlLimit} ${sqlOffset}`;
return await Self.rawSql(query, params);
diff --git a/services/loopback/common/methods/client/activeSalesPerson.js b/services/loopback/common/methods/client/activeSalesPerson.js
index 8c29f5541..bc801314b 100644
--- a/services/loopback/common/methods/client/activeSalesPerson.js
+++ b/services/loopback/common/methods/client/activeSalesPerson.js
@@ -20,10 +20,24 @@ module.exports = Self => {
});
Self.activeSalesPerson = async filter => {
+ let sqlWhere = '';
let sqlLimit = '';
let sqlOffset = '';
let params = [];
+ if (filter.where) {
+ if (filter.where.firstName) {
+ sqlWhere = `AND (worker.firstName LIKE ? OR worker.name LIKE ?)`;
+ let search = where.firstName.like;
+ params.push(search);
+ params.push(search);
+ }
+ if (filter.where.id) {
+ sqlWhere = `AND worker.id = ?`;
+ params.push(filter.where.id);
+ }
+ }
+
if (filter.limit) {
sqlLimit = `LIMIT ?`;
params.push(filter.limit);
@@ -37,10 +51,10 @@ module.exports = Self => {
`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 = 'salesPerson'
- JOIN account.roleRole inheritance ON inheritance.role = user.role AND inheritance.inheritsFrom = role.id
- WHERE user.active IS TRUE
- ORDER BY worker.firstName ASC
+ JOIN account.role role ON role.name = 'salesPerson'
+ JOIN account.roleRole inheritance ON inheritance.role = user.role AND inheritance.inheritsFrom = role.id
+ WHERE user.active IS TRUE ${sqlWhere}
+ ORDER BY worker.firstName ASC
${sqlLimit} ${sqlOffset}`;
return await Self.rawSql(query, params);
diff --git a/services/loopback/common/models/ticket-request.js b/services/loopback/common/models/ticket-request.js
new file mode 100644
index 000000000..752fab8bb
--- /dev/null
+++ b/services/loopback/common/models/ticket-request.js
@@ -0,0 +1,13 @@
+const LoopBackContext = require('loopback-context');
+
+module.exports = function(Self) {
+ Self.observe('before save', async function(ctx) {
+ if (ctx.isNewInstance) {
+ const loopBackContext = LoopBackContext.getCurrentContext();
+ let filter = {where: {userFk: loopBackContext.active.accessToken.userId}};
+ let worker = await Self.app.models.Worker.findOne(filter);
+
+ ctx.instance.requesterFk = worker.id;
+ }
+ });
+};
diff --git a/services/loopback/common/models/ticket-request.json b/services/loopback/common/models/ticket-request.json
index cfb23a14f..8a01752bf 100644
--- a/services/loopback/common/models/ticket-request.json
+++ b/services/loopback/common/models/ticket-request.json
@@ -13,19 +13,25 @@
"description": "Identifier"
},
"description": {
- "type": "String"
+ "type": "String",
+ "required": true
},
"created": {
"type": "Date"
},
"quantity": {
- "type": "Number"
+ "type": "Number",
+ "required": true
},
"price": {
"type": "Number"
},
"isOk": {
"type": "Boolean"
+ },
+ "atenderFk": {
+ "type": "Number",
+ "required": true
}
},
"relations": {