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'});
|
2018-06-06 14:54:40 +00:00
|
|
|
let exists = await Self.app.models.Ticket.findOne({where: {id: ticketFk}, fields: 'isDeleted'});
|
2018-08-02 08:54:03 +00:00
|
|
|
if (!exists || exists.isDeleted == 1 || state.alertLevel > 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2018-05-17 13:37:09 +00:00
|
|
|
};
|
|
|
|
};
|