Commit 36a64d12170d283a53853980fac4308877239d7c

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !4
1 module.exports = function(config) { 1 module.exports = function(config) {
2 2
3 var knex = require('knex')(config); 3 var knex = require('knex')(config);
4 4
5 return { 5 return {
6 getEntity: function (message) { 6 getEntity: function (message) {
7 7
8 return new Promise(function(resolve, reject) { 8 return new Promise(function(resolve, reject) {
9 9
10 knex(message.tableName).where(message.where).select('*').then(function (data) { 10 var promise;
11
12 if (message.queryString) {
13
14 promise = knex.schema.raw(message.queryString);
15 } else {
16
17 promise = knex(message.tableName).where(message.where).select('*');
18 }
19
20 promise.then(function (data) {
11 21
12 message.data = data[0]; 22 message.data = data[0];
13 resolve(message); 23 resolve(message);
14 }); 24 });
15 }); 25 });
16 } 26 }
17 } 27 }
18 } 28 }
19 29
1 const express = require('express');
2 const app = express();
3
4 const WebSocketClient = require('ws'); 1 const WebSocketClient = require('ws');
5 const config = require('./config/config.json'); 2 const config = require('./config/config.json');
6 const data = require('./data/index')(config.bo); 3 const data = require('./data/index')(config.bo);
7 4
8 app.listen(config.port);
9 app.use(express.json({limit: '50mb'}));
10
11 const client = new WebSocketClient(config.urlHO); 5 const client = new WebSocketClient(config.urlHO);
12 6
13 client.on('open', function open() { 7 client.on('open', function open() {
14 console.log('conection to socket ho is open'); 8 console.log('conection to socket ho is open');
15 9
16 client.send(JSON.stringify({ gln: config.gln, action: 'gln'})); 10 client.send(JSON.stringify({ gln: config.gln, action: 'gln'}));
17 11
18 client.on('message', function incoming(message) { 12 client.on('message', function incoming(message) {
19 13
20 message = JSON.parse(message.toString('utf8')); 14 message = JSON.parse(message.toString('utf8'));
21 15
22 switch (message.action) { 16 switch (message.action) {
23 case 'getEntity': 17 case 'getEntity':
24 18
25 data.getEntity(message).then(function(message) { 19 data.getEntity(message).then(function(message) {
26 20
27 client.send(JSON.stringify(message)); 21 client.send(JSON.stringify(message));
28 }); 22 });
29 break; 23 break;
30 default: 24 default:
31 break; 25 break;
32 } 26 }
33 }); 27 });
34 }); 28 });
35 29
36 console.log('Sevice open port ' + config.port); 30 console.log('Sevice connected to wsServer: ' + config.urlHO);
37 31