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

36 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-07-06 10:21:19 +00:00
module.exports = function(Ticket) {
Ticket.remoteMethodCtx('changeWorker', {
description: 'Change worker of tickets state',
accepts: [
{
arg: 'worker',
type: 'number',
required: true,
description: 'worker id',
http: {source: 'path'}
},
],
returns: {
arg: 'response',
type: 'boolean'
},
http: {
verb: 'put',
path: '/:worker/changeWorker'
}
});
Ticket.changeWorker = function(ctx, worker, cb) {
var tickets = ctx.req.body.tickets;
changeWorker(worker, tickets, cb);
};
var changeWorker = function(worker, tickets, cb){
var inserts = [];
var FakeProduction = Ticket.app.models.FakeProduction;
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {workerFk: worker}, function(err, info){
(err) ? cb(err, null) : cb(null, info);
});
}
}