salix/services/loopback/common/methods/ticket/isEditable.js

28 lines
912 B
JavaScript
Raw Normal View History

2018-05-17 13:37:09 +00:00
module.exports = Self => {
Self.remoteMethod('isEditable', {
description: 'Check if a ticket is editable',
accessType: 'READ',
accepts: [{
arg: 'ticketFk',
type: 'number',
required: true,
description: 'ticketFk',
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:ticketFk/isEditable`,
verb: 'get'
}
});
Self.isEditable = async ticketFk => {
let state = await Self.app.models.TicketState.findOne({where: {ticketFk: ticketFk}, fields: 'alertLevel'});
let exists = await Self.app.models.Ticket.findOne({where: {id: ticketFk}, fields: 'isDeleted'});
return (exists && state == null && exists.isDeleted == 0) || (exists.isDeleted == 0 && state.alertLevel == 0);
2018-05-17 13:37:09 +00:00
};
};