From bbfa066640a1e4a93a1666d0a79bb3ab81cc0973 Mon Sep 17 00:00:00 2001 From: gerard Date: Thu, 17 May 2018 15:37:09 +0200 Subject: [PATCH] Bug #307 CR JOAN --- .../common/methods/ticket/isEditable.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 services/loopback/common/methods/ticket/isEditable.js diff --git a/services/loopback/common/methods/ticket/isEditable.js b/services/loopback/common/methods/ticket/isEditable.js new file mode 100644 index 000000000..149a87ee1 --- /dev/null +++ b/services/loopback/common/methods/ticket/isEditable.js @@ -0,0 +1,27 @@ +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'}); + + return state != null && state.alertLevel == 0; + }; +};