diff --git a/modules/client/back/methods/client/lastActiveTickets.js b/modules/client/back/methods/client/lastActiveTickets.js index 4dc1e2c56..0337857a9 100644 --- a/modules/client/back/methods/client/lastActiveTickets.js +++ b/modules/client/back/methods/client/lastActiveTickets.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('lastActiveTickets', { - description: 'Returns the last three tickets of a client that have the alertLevel at 0 and the shiped day is gt today', + description: 'Returns the last three active tickets of a client', accessType: 'READ', accepts: [{ arg: 'id', @@ -24,16 +24,18 @@ module.exports = Self => { }); Self.lastActiveTickets = async(id, ticketId) => { + const ticket = await Self.app.models.Ticket.findById(ticketId); const query = ` SELECT t.id, t.shipped, a.name AS agencyName, w.name AS warehouseName FROM vn.ticket t JOIN vn.ticketState ts ON t.id = ts.ticketFk JOIN vn.agencyMode a ON t.agencyModeFk = a.id JOIN vn.warehouse w ON t.warehouseFk = w.id - WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 AND t.id <> ? + WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 + AND t.id <> ? AND t.warehouseFk = ? ORDER BY t.shipped LIMIT 3`; - return Self.rawSql(query, [id, ticketId]); + return Self.rawSql(query, [id, ticketId, ticket.warehouseFk]); }; };