change state ticket

This commit is contained in:
nelo 2017-06-13 13:57:40 +02:00
parent e09f60a53a
commit 6adc734f69
2 changed files with 55 additions and 0 deletions

View File

@ -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 } } };
}
}

View File

@ -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);
};