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) {
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!'));
}

View File

@ -80,12 +80,13 @@ module.exports = function(self) {
self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) {
cb(error, response);
if (error)
cb(error, null);
return response;
});
};
self.remoteMethodCtx = function(methodName, args) {
if (args.accepts !== undefined && Array.isArray(args.accepts)) {
var ctx = {
arg: 'context',
type: 'object',
@ -93,8 +94,11 @@ module.exports = function(self) {
return ctx;
}
};
if (args.accepts === undefined)
args.accepts = [];
else if (!Array.isArray(args.accepts))
args.accepts = [args.accepts];
args.accepts.unshift(ctx);
}
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 inserts = [];
var FakeProduction = TicketState.app.models.FakeProduction;
tickets.forEach(function(t) {
inserts.push({ticketFk: t, stateFk: state, employeeFk: emp});
}, this);
TicketState.create(inserts, function(err, res){
if(!err)
cb(null, res);
if(err)
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,
"type": "Number",
"forceId": false
},
"date": {
"type": "date"
}
},
"acls": [

View File

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

View File

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

View File

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

View File

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