production: asignar tickets
This commit is contained in:
parent
de71e5a454
commit
34016dfa1e
|
@ -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);
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,6 +59,12 @@
|
|||
},
|
||||
"Route": {
|
||||
"dataSource": "salix"
|
||||
},
|
||||
"ticketTracking": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"worker": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue