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

38 lines
1.1 KiB
JavaScript

module.exports = function(Self) {
Self.remoteMethod('checkEmptiness', {
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: {
arg: 'data',
type: 'boolean',
root: true
},
http: {
path: `/:id/checkEmptiness`,
verb: 'get'
}
});
Self.checkEmptiness = async id => {
const packages = await Self.app.models.TicketPackaging.find({where: {ticketFk: id}});
const services = await Self.app.models.TicketService.find({where: {ticketFk: id}});
const purchaseRequests = await Self.app.models.TicketRequest.find({where: {ticketFk: id}});
emptyTicket = !packages.length && !services.length && !purchaseRequests.length;
if (emptyTicket)
return true;
return false;
};
};