From 607c781f15a9906b8cd97c86db1a9772430378d4 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Thu, 6 Jul 2017 11:28:06 +0200 Subject: [PATCH] merge --- .../methods/ticket-state/change-worker.js | 52 +++++++++++++++++++ .../production/common/models/ticket-state.js | 1 + 2 files changed, 53 insertions(+) create mode 100644 services/production/common/methods/ticket-state/change-worker.js diff --git a/services/production/common/methods/ticket-state/change-worker.js b/services/production/common/methods/ticket-state/change-worker.js new file mode 100644 index 000000000..bc097f33f --- /dev/null +++ b/services/production/common/methods/ticket-state/change-worker.js @@ -0,0 +1,52 @@ +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/models/ticket-state.js b/services/production/common/models/ticket-state.js index 46b979506..0a6f7cbd8 100644 --- a/services/production/common/models/ticket-state.js +++ b/services/production/common/models/ticket-state.js @@ -2,4 +2,5 @@ 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