From 6adc734f69f5dbe79de64afea6b8bc0ef746ac6c Mon Sep 17 00:00:00 2001 From: nelo Date: Tue, 13 Jun 2017 13:57:40 +0200 Subject: [PATCH] change state ticket --- .../methods/ticket-state/change-state.js | 46 +++++++++++++++++++ .../production/common/models/ticket-state.js | 9 ++++ 2 files changed, 55 insertions(+) create mode 100644 services/production/common/methods/ticket-state/change-state.js create mode 100644 services/production/common/models/ticket-state.js diff --git a/services/production/common/methods/ticket-state/change-state.js b/services/production/common/methods/ticket-state/change-state.js new file mode 100644 index 000000000..99254bd66 --- /dev/null +++ b/services/production/common/methods/ticket-state/change-state.js @@ -0,0 +1,46 @@ +module.exports = function(TicketState) { + TicketState.remoteMethod('changeState', { + description: 'Change state of tickets', + accepts: [ + { + arg: 'tickets', + type: 'array', + required: true, + description: 'Array of tickets', + http: {source: 'path'} + }, + { + arg: 'state', + type: 'number', + required: true, + description: 'New state', + http: {source: 'path'} + }, + ], + returns: { + arg: 'response', + type: 'boolean' + }, + http: { + verb: 'put', + path: '/:tickets/:state/changeState' + } + }); + + TicketState.changeState = function(tickets, state, cb) { + changeState(tickets, state, cb); + }; + + var changeState = function(tickets, state, cb){ + TicketState.update(where(tickets), {"state": state}, function(error, response){ + if(!error) + cb(null, true); + cb(error); + }); + } + + var where = function(tickets){ + return {"where": {"ticketFk": {"inq": tickets } } }; + } + +} \ No newline at end of file diff --git a/services/production/common/models/ticket-state.js b/services/production/common/models/ticket-state.js new file mode 100644 index 000000000..f6890964d --- /dev/null +++ b/services/production/common/models/ticket-state.js @@ -0,0 +1,9 @@ +var app = require('../../server/server'); + +module.exports = function(TicketState) { + var models = app.models; + + // Methods + + require('../methods/ticket-state/change-state.js')(TicketState); +}; \ No newline at end of file