32 lines
957 B
JavaScript
32 lines
957 B
JavaScript
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}});
|
|
let alertLevel = state ? state.alertLevel : null;
|
|
let exists = await Self.app.models.Ticket.findOne({where: {id: ticketFk}, fields: 'isDeleted'});
|
|
if (!exists || exists.isDeleted == 1 || (alertLevel && alertLevel > 0))
|
|
return false;
|
|
|
|
return true;
|
|
};
|
|
};
|