#857 ticket/index buscador avanzado

This commit is contained in:
Gerard 2018-12-12 14:30:48 +01:00
parent e9d303ccfa
commit 832d3f7a0a
6 changed files with 67 additions and 8 deletions

View File

@ -78,9 +78,16 @@
field="filter.stateFk"
url="/api/States">
</vn-autocomplete>
<vn-textfield
vn-one
label="Order id"
model="filter.orderFk">
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-check
vn-one
label="My tickets"
label="My team"
field="filter.myTeam">
</vn-check>
</vn-horizontal>

View File

@ -8,4 +8,4 @@ Warehouse: Almacén
Sales person: Comercial
Province: Provincia
My team: Mi equipo
My tickets: Mis tickets
Order id: Id pedido

View File

@ -63,6 +63,10 @@ module.exports = Self => {
arg: 'myTeam',
type: 'Boolean',
description: `Whether to show only tickets for the current logged user team (For now it shows only the current user tickets)`
}, {
arg: 'orderFk',
type: 'Number',
description: `The order id filter`
}
],
returns: {
@ -79,10 +83,18 @@ module.exports = Self => {
let conn = Self.dataSource.connector;
let worker = await Self.app.models.Worker.findOne({
fields: ['id'],
where: {userFk: ctx.req.accessToken.userId}
where: {userFk: ctx.req.accessToken.userId},
include: [
{relation: 'collegues'}
]
});
let teamIds = [worker && worker.id];
let teamIds = [];
worker.collegues().forEach(collegue => {
teamIds.push(collegue.collegueFk);
});
console.log(teamIds);
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
@ -102,6 +114,8 @@ module.exports = Self => {
return {'a.provinceFk': value};
case 'stateFk':
return {'ts.stateFk': value};
case 'orderFk':
return {'ot.orderFk': value};
case 'myTeam':
return {'c.salesPersonFk': {inq: teamIds}};
case 'id':
@ -136,7 +150,8 @@ module.exports = Self => {
w.name AS warehouse,
am.name AS agencyMode,
st.name AS state,
wk.name AS salesPerson
wk.name AS salesPerson,
ot.orderFk AS orderFk
FROM ticket t
LEFT JOIN address a ON a.id = t.addressFk
LEFT JOIN province p ON p.id = a.provinceFk
@ -145,8 +160,11 @@ module.exports = Self => {
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
LEFT JOIN state st ON st.id = ts.stateFk
LEFT JOIN client c ON c.id = t.clientFk
LEFT JOIN worker wk ON wk.id = c.salesPersonFk`);
stmt.merge(conn.makeSuffix(filter));
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
LEFT JOIN orderTicket ot ON ot.ticketFk = t.id`);
stmt.merge(conn.makeWhere(filter.where));
stmt.merge('GROUP BY t.id');
stmt.merge(conn.makePagination(filter));
stmts.push(stmt);
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems');

View File

@ -0,0 +1,26 @@
{
"name": "WorkerTeamCollegues",
"base": "VnModel",
"options": {
"mysql": {
"table": "workerTeamCollegues"
}
},
"properties": {
"workerFk": {
"id": true,
"type": "Number"
},
"collegueFk": {
"id": true,
"type": "Number"
}
},
"relations": {
"worker": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "workerFk"
}
}
}

View File

@ -31,6 +31,11 @@
"type": "belongsTo",
"model": "Account",
"foreignKey": "userFk"
},
"collegues": {
"type": "hasMany",
"model": "WorkerTeamCollegues",
"foreignKey": "workerFk"
}
}
}

View File

@ -165,6 +165,9 @@
"WorkerTeam": {
"dataSource": "vn"
},
"WorkerTeamCollegues": {
"dataSource": "vn"
},
"TicketRequest": {
"dataSource": "vn"
},