53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
module.exports = function(Self) {
|
|
Self.remoteMethod('isEmpty', {
|
|
description: 'Checks if the ticket has no packages, componenets and purchase requests',
|
|
accessType: 'READ',
|
|
accepts: [
|
|
{
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'Ticket id',
|
|
http: {source: 'path'}
|
|
}
|
|
],
|
|
returns: {
|
|
type: 'Boolean',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/isEmpty`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.isEmpty = async(id, options) => {
|
|
const models = Self.app.models;
|
|
|
|
if ((typeof options) != 'object')
|
|
options = {};
|
|
|
|
const hasSales = await models.Sale.count({
|
|
ticketFk: id
|
|
}, options);
|
|
|
|
const hasPackages = await models.TicketPackaging.count({
|
|
ticketFk: id
|
|
}, options);
|
|
|
|
const hasServices = await models.TicketService.count({
|
|
ticketFk: id
|
|
}, options);
|
|
|
|
const hasPurchaseRequests = await models.TicketRequest.count({
|
|
ticketFk: id,
|
|
isOk: true
|
|
}, options);
|
|
|
|
const isEmpty = !hasSales && !hasPackages &&
|
|
!hasServices && !hasPurchaseRequests;
|
|
|
|
return isEmpty;
|
|
};
|
|
};
|