merge
This commit is contained in:
parent
525c8bbcf8
commit
607c781f15
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
};
|
Loading…
Reference in New Issue