diff --git a/services/production/common/methods/ticket-state/change-worker.js b/services/production/common/methods/ticket-state/change-worker.js deleted file mode 100644 index bc097f33f..000000000 --- a/services/production/common/methods/ticket-state/change-worker.js +++ /dev/null @@ -1,52 +0,0 @@ -module.exports = function(TicketState) { - TicketState.remoteMethodCtx('changeWorker', { - description: 'Change worker of tickets state', - accepts: [ - { - arg: 'user_id', - type: 'number', - required: true, - description: 'user id', - http: {source: 'path'} - }, - ], - returns: { - arg: 'response', - type: 'boolean' - }, - http: { - verb: 'post', - path: '/changeWorker' - } - }); - - TicketState.changeWorker = function(ctx, state, cb) { - var tickets = ctx.req.body.tickets; - var user_id = ctx.req.params.user_id; - - TicketState.connectToService(ctx, "client"); - - changeState(user_id, tickets, state, cb); - - TicketState.disconnectFromService("client"); - }; - - var changeWorker = function(user_id, tickets, state, cb){ - var inserts = []; - var FakeProduction = TicketState.app.models.FakeProduction; - - tickets.forEach(function(t) { - inserts.push({ticketFk: t, stateFk: state, employeeFk: user_id}); - }, this); - - TicketState.create(inserts, function(err, res){ - if(err) - cb(err, null) - else{ - FakeProduction.updateAll({ticketFk: {inq: tickets}}, {stateFk: state}, function(err, info){ - (err) ? cb(err, null) : cb(null, info); - }); - } - }); - } -} \ No newline at end of file diff --git a/services/production/common/methods/ticket/change-worker.js b/services/production/common/methods/ticket/change-worker.js new file mode 100644 index 000000000..c6572a786 --- /dev/null +++ b/services/production/common/methods/ticket/change-worker.js @@ -0,0 +1,36 @@ +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); + }); + } +} \ No newline at end of file diff --git a/services/production/common/models/ticket-state.js b/services/production/common/models/ticket-state.js index 0a6f7cbd8..46b979506 100644 --- a/services/production/common/models/ticket-state.js +++ b/services/production/common/models/ticket-state.js @@ -2,5 +2,4 @@ var app = require('../../server/server'); module.exports = function(TicketState) { require('../methods/ticket-state/change-state.js')(TicketState); - require('../methods/ticket-state/change-worker.js')(TicketState); }; \ No newline at end of file diff --git a/services/production/common/models/ticket.js b/services/production/common/models/ticket.js index 74420ec5e..d3ea5530b 100644 --- a/services/production/common/models/ticket.js +++ b/services/production/common/models/ticket.js @@ -2,4 +2,5 @@ var app = require('../../server/server'); module.exports = function(Ticket) { require('../methods/ticket/change-time.js')(Ticket); + require('../methods/ticket/change-worker.js')(Ticket); };