salix/modules/client/back/methods/client/lastActiveTickets.js

64 lines
2.0 KiB
JavaScript
Raw Normal View History

module.exports = Self => {
2019-08-09 06:04:44 +00:00
Self.remoteMethod('lastActiveTickets', {
2020-02-03 10:12:04 +00:00
description: 'Returns the last three active tickets of a client',
2019-05-22 10:35:24 +00:00
accessType: 'READ',
2021-07-08 13:53:30 +00:00
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'Client id',
http: {source: 'path'}
},
{
arg: 'ticketId',
type: 'number',
required: true
}
],
returns: {
2021-07-08 13:53:30 +00:00
type: ['object'],
root: true
},
http: {
2019-08-09 06:04:44 +00:00
path: `/:id/lastActiveTickets`,
verb: 'GET'
}
});
2021-07-08 13:53:30 +00:00
Self.lastActiveTickets = async(id, ticketId, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
2023-01-16 14:18:24 +00:00
const date = Date.vnNew();
2022-06-09 11:33:01 +00:00
date.setHours(0, 0, 0, 0);
2021-07-08 13:53:30 +00:00
const ticket = await Self.app.models.Ticket.findById(ticketId, null, myOptions);
2019-08-09 06:04:44 +00:00
const query = `
2023-01-16 14:18:24 +00:00
SELECT
t.id,
t.shipped,
2023-01-16 14:18:24 +00:00
a.name AS agencyName,
w.name AS warehouseName,
ad.nickname AS nickname,
ad.city AS city,
ad.postalCode AS postalCode,
ad.street AS street,
pr.name AS name
FROM 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
JOIN vn.address ad ON t.addressFk = ad.id
JOIN vn.province pr ON ad.provinceFk = pr.id
2023-01-16 14:18:24 +00:00
WHERE t.shipped >= ? AND t.clientFk = ? AND ts.alertLevel = 0
2021-02-12 15:41:29 +00:00
AND t.id <> ? AND t.warehouseFk = ?
ORDER BY t.shipped
2020-09-30 10:24:33 +00:00
LIMIT 10`;
2019-08-09 06:04:44 +00:00
2022-06-09 11:33:01 +00:00
return Self.rawSql(query, [date, id, ticketId, ticket.warehouseFk], myOptions);
};
};
2020-09-30 11:35:37 +00:00