diff --git a/services/production/common/methods/ticket/change-worker.js b/services/production/common/methods/ticket/change-worker.js index c1fcea080..896c8a7f9 100644 --- a/services/production/common/methods/ticket/change-worker.js +++ b/services/production/common/methods/ticket/change-worker.js @@ -1,5 +1,5 @@ -module.exports = function(Ticket) { - Ticket.remoteMethodCtx('changeWorker', { +module.exports = function(Self) { + Self.remoteMethodCtx('changeWorker', { description: 'Change worker of tickets state', accepts: [ { @@ -11,7 +11,7 @@ module.exports = function(Ticket) { } ], returns: { - arg: 'response', + arg: 'response', type: 'boolean' }, http: { @@ -19,17 +19,29 @@ module.exports = function(Ticket) { path: '/:worker/changeWorker' } }); - - Ticket.changeWorker = function(ctx, worker, cb) { - var tickets = ctx.req.body.tickets; + + Self.changeWorker = function(ctx, worker, cb) { + let tickets = ctx.req.body.tickets; changeWorker(worker, tickets, cb); }; - let changeWorker = function(worker, tickets, cb) { - var FakeProduction = Ticket.app.models.FakeProduction; - - FakeProduction.updateAll({ticketFk: {inq: tickets}}, {workerFk: worker}, function(err, info){ - (err) ? cb(err, null) : cb(null, info); + 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); }); - }; + } }; diff --git a/services/production/common/models/ticket-tracking.json b/services/production/common/models/ticket-tracking.json new file mode 100644 index 000000000..bdf54191a --- /dev/null +++ b/services/production/common/models/ticket-tracking.json @@ -0,0 +1,33 @@ +{ + "name": "ticketTracking", + "base": "VnModel", + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "created": { + "type": "Date", + "required": false + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "state": { + "type": "belongsTo", + "model": "State", + "foreignKey": "stateFk" + }, + "worker": { + "type": "belongsTo", + "model": "worker", + "foreignKey": "workerFk" + } + } + } + \ No newline at end of file diff --git a/services/production/common/models/worker.json b/services/production/common/models/worker.json new file mode 100644 index 000000000..cf34ee0c1 --- /dev/null +++ b/services/production/common/models/worker.json @@ -0,0 +1,31 @@ +{ + "name": "worker", + "base": "VnModel", + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "workerCode": { + "type": "String" + }, + "firstName": { + "type": "String" + }, + "name": { + "type": "String" + } + , + "phone": { + "type": "String" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "User", + "foreignKey": "userFk" + } + } +} \ No newline at end of file diff --git a/services/production/server/model-config.json b/services/production/server/model-config.json index d4d72f77d..07e336834 100644 --- a/services/production/server/model-config.json +++ b/services/production/server/model-config.json @@ -59,6 +59,12 @@ }, "Route": { "dataSource": "salix" + }, + "ticketTracking": { + "dataSource": "vn" + }, + "worker": { + "dataSource": "vn" } }