production: asignar tickets

This commit is contained in:
Daniel Herrero 2017-12-12 12:26:18 +01:00
parent de71e5a454
commit 34016dfa1e
4 changed files with 94 additions and 12 deletions

View File

@ -1,5 +1,5 @@
module.exports = function(Ticket) { module.exports = function(Self) {
Ticket.remoteMethodCtx('changeWorker', { Self.remoteMethodCtx('changeWorker', {
description: 'Change worker of tickets state', description: 'Change worker of tickets state',
accepts: [ accepts: [
{ {
@ -11,7 +11,7 @@ module.exports = function(Ticket) {
} }
], ],
returns: { returns: {
arg: 'response', arg: 'response',
type: 'boolean' type: 'boolean'
}, },
http: { http: {
@ -19,17 +19,29 @@ module.exports = function(Ticket) {
path: '/:worker/changeWorker' path: '/:worker/changeWorker'
} }
}); });
Ticket.changeWorker = function(ctx, worker, cb) { Self.changeWorker = function(ctx, worker, cb) {
var tickets = ctx.req.body.tickets; let tickets = ctx.req.body.tickets;
changeWorker(worker, tickets, cb); changeWorker(worker, tickets, cb);
}; };
let changeWorker = function(worker, tickets, cb) { function changeWorker(worker, tickets, cb) {
var FakeProduction = Ticket.app.models.FakeProduction; let ticketTracking = Self.app.models.ticketTracking;
let toSave = [];
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {workerFk: worker}, function(err, info){ for (let ticket of tickets) {
(err) ? cb(err, null) : cb(null, info); toSave.push(
{
stateFk: 20,
ticketFk: ticket,
workerFk: worker
}
);
}
ticketTracking.create(toSave, function(err, info) {
if (err)
cb(err, null);
else
cb(null, info);
}); });
}; }
}; };

View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

@ -59,6 +59,12 @@
}, },
"Route": { "Route": {
"dataSource": "salix" "dataSource": "salix"
},
"ticketTracking": {
"dataSource": "vn"
},
"worker": {
"dataSource": "vn"
} }
} }