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) {
Ticket.remoteMethodCtx('changeWorker', {
module.exports = function(Self) {
Self.remoteMethodCtx('changeWorker', {
description: 'Change worker of tickets state',
accepts: [
{
@ -20,16 +20,28 @@ module.exports = function(Ticket) {
}
});
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);
});
};
}
};

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": {
"dataSource": "salix"
},
"ticketTracking": {
"dataSource": "vn"
},
"worker": {
"dataSource": "vn"
}
}