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

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-12-12 11:26:18 +00:00
module.exports = function(Self) {
Self.remoteMethodCtx('changeWorker', {
2017-07-06 10:21:19 +00:00
description: 'Change worker of tickets state',
accepts: [
{
arg: 'worker',
type: 'number',
required: true,
description: 'worker id',
http: {source: 'path'}
2017-10-25 11:47:39 +00:00
}
2017-07-06 10:21:19 +00:00
],
returns: {
2017-12-12 11:26:18 +00:00
arg: 'response',
2017-07-06 10:21:19 +00:00
type: 'boolean'
},
http: {
verb: 'put',
path: '/:worker/changeWorker'
}
});
2017-12-12 11:26:18 +00:00
Self.changeWorker = function(ctx, worker, cb) {
let tickets = ctx.req.body.tickets;
2017-07-06 10:21:19 +00:00
changeWorker(worker, tickets, cb);
};
2017-12-12 11:26:18 +00:00
function changeWorker(worker, tickets, cb) {
let ticketTracking = Self.app.models.ticketTracking;
let toSave = [];
for (let ticket of tickets) {
toSave.push(
{
stateFk: 20,
ticketFk: ticket,
workerFk: worker
}
);
}
ticketTracking.create(toSave, function(err, info) {
if (err)
cb(err, null);
else
cb(null, info);
2017-07-06 10:21:19 +00:00
});
2017-12-12 11:26:18 +00:00
}
2017-10-25 11:47:39 +00:00
};