salix/modules/ticket/back/methods/ticket/threeLastActive.js

36 lines
1.2 KiB
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethod('threeLastActive', {
description: 'Returns the last three tickets of a client that have the alertLevel at 0 and the shiped day is gt today',
2019-05-22 10:35:24 +00:00
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'object',
required: true,
description: 'client id, ticketFk'
}],
returns: {
type: [this.modelName],
root: true
},
http: {
path: `/threeLastActive`,
verb: 'GET'
}
});
Self.threeLastActive = async params => {
let query = `
2019-06-19 12:40:47 +00:00
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
2019-08-06 05:36:26 +00:00
WHERE t.shipped >= CURDATE() AND t.clientFk = ?
AND ts.alertLevel = 0 AND t.id <> ?
ORDER BY t.shipped
2019-08-06 05:36:26 +00:00
LIMIT 5`;
let tickets = await Self.rawSql(query, [params.clientFk, params.ticketFk]);
return tickets;
};
};