change state

message send
change time
This commit is contained in:
nelo 2017-06-28 08:57:33 +02:00
parent fabe0cde7c
commit 80121de6c3
10 changed files with 126 additions and 38 deletions

View File

@ -66,7 +66,7 @@ export default class ProductionIndex {
); );
} }
_sendMessage(tickets) { _sendMessage(tickets) {
this.$http.post(`/production/api/TicketStates/messageSend`, {tickets: tickets}).then( this.$http.post(`/production/api/FakeProductions/messageSend`, {tickets: tickets}).then(
() => { () => {
this.vnApp.showMessage(this.$translate.instant('Success: message send!')); this.vnApp.showMessage(this.$translate.instant('Success: message send!'));
} }

View File

@ -80,21 +80,25 @@ module.exports = function(self) {
self.rawSql = function(query, params, cb) { self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) { this.dataSource.connector.execute(query, params, function(error, response) {
cb(error, response); if (error)
cb(error, null);
return response;
}); });
}; };
self.remoteMethodCtx = function(methodName, args) { self.remoteMethodCtx = function(methodName, args) {
if (args.accepts !== undefined && Array.isArray(args.accepts)) { var ctx = {
var ctx = { arg: 'context',
arg: 'context', type: 'object',
type: 'object', http: function(ctx) {
http: function(ctx) { return ctx;
return ctx; }
} };
}; if (args.accepts === undefined)
args.accepts.unshift(ctx); args.accepts = [];
} else if (!Array.isArray(args.accepts))
args.accepts = [args.accepts];
args.accepts.unshift(ctx);
this.remoteMethod(methodName, args); this.remoteMethod(methodName, args);
}; };

View File

@ -0,0 +1,31 @@
module.exports = function(FakeProduction) {
FakeProduction.remoteMethodCtx('messageSend', {
description: 'Send message to salesPerson of one array of tickets',
returns: {
arg: 'response',
type: 'message'
},
http: {
path: '/messageSend'
}
});
FakeProduction.messageSend = function(ctx, cb) {
var tickets = ctx.req.body.tickets;
var elements = [];
tickets.forEach(function(t) {
elements.push({salesPerson: 'nelo', message: `Revisa el tickete ${t.ticketFk}`});
}, this);
messageSend(elements, cb);
};
var messageSend = function(elements, cb){
elements.forEach(function(e) {
var query = `select messageSend(?, ?)`;
var params = [e.salesPerson, e.message];
FakeProduction.rawSql(query, params, cb);
}, this);
cb(null, "Mensaje enviado");
}
}

View File

@ -37,16 +37,20 @@ module.exports = function(TicketState) {
var changeState = function(emp, tickets, state, cb){ var changeState = function(emp, tickets, state, cb){
var inserts = []; var inserts = [];
var FakeProduction = TicketState.app.models.FakeProduction;
tickets.forEach(function(t) { tickets.forEach(function(t) {
inserts.push({ticketFk: t, stateFk: state, employeeFk: emp}); inserts.push({ticketFk: t, stateFk: state, employeeFk: emp});
}, this); }, this);
TicketState.create(inserts, function(err, res){ TicketState.create(inserts, function(err, res){
if(!err) if(err)
cb(null, res); cb(err, null)
else{
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {stateFk: state}, function(err, info){
(err) ? cb(err, null) : cb(null, info);
});
}
}); });
} }
} }

View File

@ -0,0 +1,36 @@
module.exports = function(Ticket) {
Ticket.remoteMethodCtx('changeTime', {
description: 'List tickets for production',
accepts: {
arg: 'time',
type: 'string',
required: true,
description: 'New time of ticket',
http: {source: 'path'}
},
http: {
verb: 'get',
path: '/changeTime'
}
});
Ticket.changeTime = function(ctx, time, cb) {
var tickets = ctx.req.body.tickets;
};
var changeTime = function(tickets, time, cb){
var FakeProduction = Ticket.app.models.FakeProduction;
time = `CONCAT(DATE(Fecha), ' ${time}')`;
Ticket.updateAll({id: {inq: tickets}}, {date: time}, function(err, res){
if(err)
cb(err, null)
else
FakeProduction.updateAll({id: {inq: tickets}}, {date: time}, function(err, res){
(err) ? cb(err, null) : cb(null, res)
});
});
}
}

View File

@ -7,6 +7,9 @@
"id": true, "id": true,
"type": "Number", "type": "Number",
"forceId": false "forceId": false
},
"date": {
"type": "date"
} }
}, },
"acls": [ "acls": [

View File

@ -5,4 +5,5 @@ module.exports = function(FakeProduction) {
// Methods // Methods
require('../methods/fake-production/list.js')(FakeProduction); require('../methods/fake-production/list.js')(FakeProduction);
require('../methods/fake-production/message-send.js')(FakeProduction);
}; };

View File

@ -80,21 +80,25 @@ module.exports = function(self) {
self.rawSql = function(query, params, cb) { self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) { this.dataSource.connector.execute(query, params, function(error, response) {
cb(error, response); if (error)
cb(error, null);
return response;
}); });
}; };
self.remoteMethodCtx = function(methodName, args) { self.remoteMethodCtx = function(methodName, args) {
if (args.accepts !== undefined && Array.isArray(args.accepts)) { var ctx = {
var ctx = { arg: 'context',
arg: 'context', type: 'object',
type: 'object', http: function(ctx) {
http: function(ctx) { return ctx;
return ctx; }
} };
}; if (args.accepts === undefined)
args.accepts.unshift(ctx); args.accepts = [];
} else if (!Array.isArray(args.accepts))
args.accepts = [args.accepts];
args.accepts.unshift(ctx);
this.remoteMethod(methodName, args); this.remoteMethod(methodName, args);
}; };

View File

@ -4,4 +4,5 @@ module.exports = function(Ticket) {
var models = app.models; var models = app.models;
// Methods // Methods
require('../methods/ticket/change-time.js')(Ticket);
}; };

View File

@ -80,21 +80,25 @@ module.exports = function(self) {
self.rawSql = function(query, params, cb) { self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) { this.dataSource.connector.execute(query, params, function(error, response) {
cb(error, response); if (error)
cb(error, null);
return response;
}); });
}; };
self.remoteMethodCtx = function(methodName, args) { self.remoteMethodCtx = function(methodName, args) {
if (args.accepts !== undefined && Array.isArray(args.accepts)) { var ctx = {
var ctx = { arg: 'context',
arg: 'context', type: 'object',
type: 'object', http: function(ctx) {
http: function(ctx) { return ctx;
return ctx; }
} };
}; if (args.accepts === undefined)
args.accepts.unshift(ctx); args.accepts = [];
} else if (!Array.isArray(args.accepts))
args.accepts = [args.accepts];
args.accepts.unshift(ctx);
this.remoteMethod(methodName, args); this.remoteMethod(methodName, args);
}; };