Commit 715d6bb331b565e930022c0c3fc021ae43f5542e
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !13
Showing
1 changed file
 
Show diff stats
index.js
| 1 | const WebSocketClient = require('ws'); | 1 | const WebSocketClient = require('ws'); | 
| 2 | const config = require('./config/config.json'); | 2 | const config = require('./config/config.json'); | 
| 3 | const data = require('./data/index')(config.bo); | 3 | const data = require('./data/index')(config.bo); | 
| 4 | module.exports = knex = require('knex')(config.bo); | 4 | module.exports = | 
| 5 | knex = require('knex')(config.bo), | ||
| 6 | moment = require('moment'); | ||
| 7 | |||
| 5 | 8 | ||
| 6 | const client = new WebSocketClient(config.urlHO); | 9 | const client = new WebSocketClient(config.urlHO); | 
| 7 | 10 | ||
| 8 | client.on('open', function open() { | 11 | client.on('open', function open() { | 
| 9 | console.log('conection to socket ho is open'); | 12 | console.log('conection to socket ho is open'); | 
| 10 | 13 | ||
| 11 | client.send(JSON.stringify({ gln: config.gln, action: 'gln'})); | 14 | client.send(JSON.stringify({ gln: config.gln, action: 'gln'})); | 
| 12 | 15 | ||
| 13 | client.on('message', function incoming(message) { | 16 | client.on('message', function incoming(message) { | 
| 14 | 17 | ||
| 15 | message = JSON.parse(message.toString('utf8')); | 18 | message = JSON.parse(message.toString('utf8')); | 
| 16 | 19 | ||
| 17 | switch (message.action) { | 20 | switch (message.action) { | 
| 18 | case 'getEntity': | 21 | case 'getEntity': | 
| 19 | 22 | ||
| 20 | data.getEntity(message).then(function(message) { | 23 | data.getEntity(message).then(function(message) { | 
| 21 | 24 | ||
| 22 | client.send(JSON.stringify(message)); | 25 | client.send(JSON.stringify(message)); | 
| 23 | }); | 26 | }); | 
| 24 | break; | 27 | break; | 
| 25 | 28 | ||
| 26 | case 'comprobante': | 29 | case 'comprobante': | 
| 27 | console.log('recibiendo comprobante') | 30 | console.log('recibiendo comprobante') | 
| 28 | data.guardarComprobante(message.req).then(() => { | 31 | data.guardarComprobante(message.req).then(() => { | 
| 29 | console.log('se guardó'); | 32 | console.log('se guardó'); | 
| 30 | client.send(JSON.stringify('ok')); | 33 | client.send(JSON.stringify('ok')); | 
| 31 | }).catch((ee) => { | 34 | }).catch((ee) => { | 
| 32 | console.log('no se guardó' + ee); | 35 | console.log('no se guardó' + ee); | 
| 33 | client.send(JSON.stringify('bad')); | 36 | client.send(JSON.stringify('bad')); | 
| 34 | }); | 37 | }); | 
| 35 | 38 | ||
| 36 | break; | 39 | break; | 
| 37 | 40 | ||
| 38 | default: | 41 | default: | 
| 39 | break; | 42 | break; | 
| 40 | } | 43 | } | 
| 41 | }); | 44 | }); | 
| 42 | }); | 45 | }); | 
| 43 | 46 | ||
| 44 | client.on('error', function(e) { | 47 | client.on('error', function(e) { | 
| 45 | console.log(e); | 48 | console.log(e); | 
| 46 | }) | 49 | }) | 
| 47 | 50 | ||
| 48 | console.log('Sevice connected to wsServer: ' + config.urlHO); | 51 | console.log('Sevice connected to wsServer: ' + config.urlHO); | 
| 49 | 52 |