#857 ticket/index buscador avanzado
This commit is contained in:
parent
e9d303ccfa
commit
832d3f7a0a
|
@ -78,9 +78,16 @@
|
||||||
field="filter.stateFk"
|
field="filter.stateFk"
|
||||||
url="/api/States">
|
url="/api/States">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
<vn-textfield
|
||||||
|
vn-one
|
||||||
|
label="Order id"
|
||||||
|
model="filter.orderFk">
|
||||||
|
</vn-textfield>
|
||||||
|
</vn-horizontal>
|
||||||
|
<vn-horizontal>
|
||||||
<vn-check
|
<vn-check
|
||||||
vn-one
|
vn-one
|
||||||
label="My tickets"
|
label="My team"
|
||||||
field="filter.myTeam">
|
field="filter.myTeam">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
|
|
@ -8,4 +8,4 @@ Warehouse: Almacén
|
||||||
Sales person: Comercial
|
Sales person: Comercial
|
||||||
Province: Provincia
|
Province: Provincia
|
||||||
My team: Mi equipo
|
My team: Mi equipo
|
||||||
My tickets: Mis tickets
|
Order id: Id pedido
|
|
@ -63,6 +63,10 @@ module.exports = Self => {
|
||||||
arg: 'myTeam',
|
arg: 'myTeam',
|
||||||
type: 'Boolean',
|
type: 'Boolean',
|
||||||
description: `Whether to show only tickets for the current logged user team (For now it shows only the current user tickets)`
|
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: {
|
returns: {
|
||||||
|
@ -79,10 +83,18 @@ module.exports = Self => {
|
||||||
let conn = Self.dataSource.connector;
|
let conn = Self.dataSource.connector;
|
||||||
|
|
||||||
let worker = await Self.app.models.Worker.findOne({
|
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) => {
|
let where = buildFilter(ctx.args, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
|
@ -102,6 +114,8 @@ module.exports = Self => {
|
||||||
return {'a.provinceFk': value};
|
return {'a.provinceFk': value};
|
||||||
case 'stateFk':
|
case 'stateFk':
|
||||||
return {'ts.stateFk': value};
|
return {'ts.stateFk': value};
|
||||||
|
case 'orderFk':
|
||||||
|
return {'ot.orderFk': value};
|
||||||
case 'myTeam':
|
case 'myTeam':
|
||||||
return {'c.salesPersonFk': {inq: teamIds}};
|
return {'c.salesPersonFk': {inq: teamIds}};
|
||||||
case 'id':
|
case 'id':
|
||||||
|
@ -136,7 +150,8 @@ module.exports = Self => {
|
||||||
w.name AS warehouse,
|
w.name AS warehouse,
|
||||||
am.name AS agencyMode,
|
am.name AS agencyMode,
|
||||||
st.name AS state,
|
st.name AS state,
|
||||||
wk.name AS salesPerson
|
wk.name AS salesPerson,
|
||||||
|
ot.orderFk AS orderFk
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN address a ON a.id = t.addressFk
|
LEFT JOIN address a ON a.id = t.addressFk
|
||||||
LEFT JOIN province p ON p.id = a.provinceFk
|
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 ticketState ts ON ts.ticketFk = t.id
|
||||||
LEFT JOIN state st ON st.id = ts.stateFk
|
LEFT JOIN state st ON st.id = ts.stateFk
|
||||||
LEFT JOIN client c ON c.id = t.clientFk
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk`);
|
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
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(stmt);
|
||||||
|
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems');
|
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems');
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,11 @@
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Account",
|
"model": "Account",
|
||||||
"foreignKey": "userFk"
|
"foreignKey": "userFk"
|
||||||
|
},
|
||||||
|
"collegues": {
|
||||||
|
"type": "hasMany",
|
||||||
|
"model": "WorkerTeamCollegues",
|
||||||
|
"foreignKey": "workerFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -165,6 +165,9 @@
|
||||||
"WorkerTeam": {
|
"WorkerTeam": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"WorkerTeamCollegues": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"TicketRequest": {
|
"TicketRequest": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue