salix/services/loopback/common/methods/ticket/changeWorker.js

48 lines
1.2 KiB
JavaScript

module.exports = function(Self) {
Self.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'
}
});
Self.changeWorker = function(ctx, worker, cb) {
let tickets = ctx.req.body.tickets;
changeWorker(worker, tickets, cb);
};
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);
});
}
};