From 80121de6c330283ac4b5f77d4f1fe4b5a7471fef Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 28 Jun 2017 08:57:33 +0200 Subject: [PATCH] change state message send change time --- client/production/src/index/index.js | 2 +- services/client/common/models/my-model.js | 26 ++++++++------ .../methods/fake-production/message-send.js | 31 ++++++++++++++++ .../methods/ticket-state/change-state.js | 12 ++++--- .../common/methods/ticket/change-time.js | 36 +++++++++++++++++++ services/production/common/models/Ticket.json | 3 ++ .../common/models/fake-production.js | 1 + services/production/common/models/my-model.js | 26 ++++++++------ services/production/common/models/ticket.js | 1 + services/service/models/my-model.js | 26 ++++++++------ 10 files changed, 126 insertions(+), 38 deletions(-) create mode 100644 services/production/common/methods/fake-production/message-send.js create mode 100644 services/production/common/methods/ticket/change-time.js diff --git a/client/production/src/index/index.js b/client/production/src/index/index.js index f56052679..b2d73953f 100644 --- a/client/production/src/index/index.js +++ b/client/production/src/index/index.js @@ -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!')); } diff --git a/services/client/common/models/my-model.js b/services/client/common/models/my-model.js index 007b84faf..754e538a8 100644 --- a/services/client/common/models/my-model.js +++ b/services/client/common/models/my-model.js @@ -80,21 +80,25 @@ 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', - http: function(ctx) { - return ctx; - } - }; - args.accepts.unshift(ctx); - } + var ctx = { + arg: 'context', + type: 'object', + http: function(ctx) { + 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); }; diff --git a/services/production/common/methods/fake-production/message-send.js b/services/production/common/methods/fake-production/message-send.js new file mode 100644 index 000000000..d17073bd4 --- /dev/null +++ b/services/production/common/methods/fake-production/message-send.js @@ -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"); + } +} \ No newline at end of file diff --git a/services/production/common/methods/ticket-state/change-state.js b/services/production/common/methods/ticket-state/change-state.js index 5384ba86f..2be312534 100644 --- a/services/production/common/methods/ticket-state/change-state.js +++ b/services/production/common/methods/ticket-state/change-state.js @@ -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); + }); + } }); } - - } \ No newline at end of file diff --git a/services/production/common/methods/ticket/change-time.js b/services/production/common/methods/ticket/change-time.js new file mode 100644 index 000000000..78e328cb7 --- /dev/null +++ b/services/production/common/methods/ticket/change-time.js @@ -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) + }); + }); + } +} \ No newline at end of file diff --git a/services/production/common/models/Ticket.json b/services/production/common/models/Ticket.json index 4ae89da10..fd2c5b9c1 100644 --- a/services/production/common/models/Ticket.json +++ b/services/production/common/models/Ticket.json @@ -7,6 +7,9 @@ "id": true, "type": "Number", "forceId": false + }, + "date": { + "type": "date" } }, "acls": [ diff --git a/services/production/common/models/fake-production.js b/services/production/common/models/fake-production.js index f7f277b99..912d025b1 100644 --- a/services/production/common/models/fake-production.js +++ b/services/production/common/models/fake-production.js @@ -5,4 +5,5 @@ module.exports = function(FakeProduction) { // Methods require('../methods/fake-production/list.js')(FakeProduction); + require('../methods/fake-production/message-send.js')(FakeProduction); }; \ No newline at end of file diff --git a/services/production/common/models/my-model.js b/services/production/common/models/my-model.js index 007b84faf..754e538a8 100644 --- a/services/production/common/models/my-model.js +++ b/services/production/common/models/my-model.js @@ -80,21 +80,25 @@ 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', - http: function(ctx) { - return ctx; - } - }; - args.accepts.unshift(ctx); - } + var ctx = { + arg: 'context', + type: 'object', + http: function(ctx) { + 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); }; diff --git a/services/production/common/models/ticket.js b/services/production/common/models/ticket.js index b3b9bd018..556a224a4 100644 --- a/services/production/common/models/ticket.js +++ b/services/production/common/models/ticket.js @@ -4,4 +4,5 @@ module.exports = function(Ticket) { var models = app.models; // Methods + require('../methods/ticket/change-time.js')(Ticket); }; \ No newline at end of file diff --git a/services/service/models/my-model.js b/services/service/models/my-model.js index 007b84faf..754e538a8 100644 --- a/services/service/models/my-model.js +++ b/services/service/models/my-model.js @@ -80,21 +80,25 @@ 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', - http: function(ctx) { - return ctx; - } - }; - args.accepts.unshift(ctx); - } + var ctx = { + arg: 'context', + type: 'object', + http: function(ctx) { + 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); };