2024-03-26 09:13:57 +00:00
|
|
|
module.exports = Self => {
|
2024-03-26 11:40:44 +00:00
|
|
|
Self.remoteMethod('hasUncheckedTicket', {
|
2024-03-26 09:13:57 +00:00
|
|
|
description:
|
|
|
|
'Get boolean if the collection of ticket has a ticket not checked',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'ticketFk',
|
2024-03-27 06:47:36 +00:00
|
|
|
type: 'integer',
|
2024-03-26 09:13:57 +00:00
|
|
|
required: true,
|
|
|
|
description: 'Ticket id'
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'boolean',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2024-03-26 11:40:44 +00:00
|
|
|
path: `/hasUncheckedTicket`,
|
2024-03-26 09:13:57 +00:00
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-27 06:26:11 +00:00
|
|
|
Self.hasUncheckedTicket = async(ticketFk, options) => {
|
2024-03-26 10:06:14 +00:00
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2024-03-26 09:13:57 +00:00
|
|
|
const result = await Self.rawSql(`
|
|
|
|
SELECT tc2.ticketFk
|
|
|
|
FROM vn.ticketCollection tc
|
|
|
|
JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk
|
|
|
|
LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk
|
|
|
|
JOIN vn.state s ON s.id = ts.stateFk
|
|
|
|
JOIN vn.state s2 ON s2.code = 'CHECKED'
|
|
|
|
WHERE tc.ticketFk = ? AND s.order < s2.id
|
|
|
|
LIMIT 1;`,
|
2024-03-26 10:06:14 +00:00
|
|
|
[ticketFk], myOptions);
|
2024-03-26 09:13:57 +00:00
|
|
|
return result.length > 0 && result[0]['ticketFk'] > 0;
|
|
|
|
};
|
|
|
|
};
|