salix/services/production/common/methods/ticket-state/change-state.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-06-13 11:57:40 +00:00
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 } } };
}
}