Commit e36a85219133cc0417bc13e11d8aad9382e53816
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !3
Showing
2 changed files
Show diff stats
data/index.js
| ... | ... | @@ -3,9 +3,16 @@ module.exports = function(config) { |
| 3 | 3 | var knex = require('knex')(config); |
| 4 | 4 | |
| 5 | 5 | return { |
| 6 | - getEntity: function (table, where) { | |
| 6 | + getEntity: function (message) { | |
| 7 | 7 | |
| 8 | - return knex(table).where(where).select('*'); | |
| 8 | + return new Promise(function(resolve, reject) { | |
| 9 | + | |
| 10 | + knex(message.tableName).where(message.where).select('*').then(function (data) { | |
| 11 | + | |
| 12 | + message.data = data[0]; | |
| 13 | + resolve(message); | |
| 14 | + }); | |
| 15 | + }); | |
| 9 | 16 | } |
| 10 | 17 | } |
| 11 | 18 | } |
index.js
| ... | ... | @@ -13,16 +13,18 @@ const client = new WebSocketClient(config.urlHO); |
| 13 | 13 | client.on('open', function open() { |
| 14 | 14 | console.log('conection to socket ho is open'); |
| 15 | 15 | |
| 16 | - client.send(JSON.stringify({ gln: config.gln, action: 'gnl'})); | |
| 16 | + client.send(JSON.stringify({ gln: config.gln, action: 'gln'})); | |
| 17 | 17 | |
| 18 | 18 | client.on('message', function incoming(message) { |
| 19 | 19 | |
| 20 | - message = message.data.toString('utf8'); | |
| 20 | + message = JSON.parse(message.toString('utf8')); | |
| 21 | 21 | |
| 22 | - switch (message) { | |
| 23 | - case message.action == 'getEntity': | |
| 24 | - data.getEntity(message.tableName, message.where || {}).then(function(data) { | |
| 25 | - client.send(data); | |
| 22 | + switch (message.action) { | |
| 23 | + case 'getEntity': | |
| 24 | + | |
| 25 | + data.getEntity(message).then(function(message) { | |
| 26 | + | |
| 27 | + client.send(JSON.stringify(message)); | |
| 26 | 28 | }); |
| 27 | 29 | break; |
| 28 | 30 | default: |