Commit e6d8782c4703646d9ecf89148eed4566061c00df
1 parent
190383cd6c
Exists in
master
fix date time idk wtf
Showing
3 changed files
with
33 additions
and
33 deletions
Show diff stats
recadv/index.js
| 1 | 1 | module.exports = function(comprobante, cuerpos) { |
| 2 | 2 | |
| 3 | - var idTransaccion = comprobante.idTransaccion; | |
| 3 | + return new Promise((resolve, reject) => { | |
| 4 | 4 | |
| 5 | - knex('planex_transacciones') | |
| 6 | - .where({ id: idTransaccion } ) | |
| 7 | - .then(function(transax) { | |
| 5 | + var idTransaccion = comprobante.idTransaccion; | |
| 8 | 6 | |
| 9 | - transax = transax[0]; | |
| 7 | + knex('planex_transacciones') | |
| 8 | + .where({ id: idTransaccion } ) | |
| 9 | + .then(function(transax) { | |
| 10 | 10 | |
| 11 | - fs.readFile(config.dirDestino + '\\' + transax.archivoRecibido, 'utf8', function(err, fileString) { | |
| 11 | + transax = transax[0]; | |
| 12 | 12 | |
| 13 | - if (err) { | |
| 14 | - console.log(err); | |
| 15 | - return; | |
| 16 | - } | |
| 13 | + fs.readFile(config.dirDestino + '\\' + transax.archivoRecibido, 'utf8', (err, fileString) => { | |
| 17 | 14 | |
| 18 | - var planex = require('../planex')(fileString); | |
| 15 | + if (err) { | |
| 16 | + reject(err); | |
| 17 | + return; | |
| 18 | + } | |
| 19 | 19 | |
| 20 | - var result = require('./todos')(planex, cuerpos, fileString, idTransaccion); | |
| 20 | + var planex = require('../planex')(fileString); | |
| 21 | 21 | |
| 22 | - var nombreRecadv = 'RECADV_' + planex.identificaxMensaje.idMensaje + '.txt'; | |
| 22 | + var result = require('./todos')(planex, cuerpos, fileString, idTransaccion); | |
| 23 | 23 | |
| 24 | - fs.writeFile(config.dirRecadv + '/' + nombreRecadv, result, function(err) { | |
| 24 | + var nombreRecadv = 'RECADV_' + planex.identificaxMensaje.idMensaje + '.txt'; | |
| 25 | 25 | |
| 26 | - if (err) return console.log(err); | |
| 26 | + fs.writeFile(config.dirRecadv + '/' + nombreRecadv, result, err => { | |
| 27 | 27 | |
| 28 | - knex('planex_transacciones') | |
| 29 | - .where({ id: idTransaccion }) | |
| 30 | - .update({ archivoEnviado: nombreRecadv, estado: 1 }) | |
| 31 | - .then(function() { | |
| 28 | + if (err) return reject(err); | |
| 32 | 29 | |
| 33 | - console.log('Archivo Pruebas guardado'); | |
| 34 | - }); | |
| 30 | + knex('planex_transacciones') | |
| 31 | + .where({ id: idTransaccion }) | |
| 32 | + .update({ archivoEnviado: nombreRecadv, estado: 1 }) | |
| 33 | + .then(resolve) | |
| 34 | + .catch(reject); | |
| 35 | + | |
| 36 | + }); | |
| 35 | 37 | |
| 36 | 38 | }); |
| 37 | 39 | |
| 38 | - }); | |
| 40 | + }) | |
| 41 | + .catch(reject); | |
| 39 | 42 | |
| 40 | - }); | |
| 43 | + }); | |
| 41 | 44 | } |
rutas/comprobantes.js
| ... | ... | @@ -42,10 +42,7 @@ router.get('/comprobantes/:gln*?', function(req, res) { |
| 42 | 42 | |
| 43 | 43 | router.post('/comprobante', function(req, res) { |
| 44 | 44 | |
| 45 | - console.log(req.body); | |
| 46 | - | |
| 47 | - require('../recadv')( | |
| 48 | - JSON.parse(JSON.stringify(req.body.cabecera)), | |
| 45 | + var recadv = require('../recadv')(JSON.parse(JSON.stringify(req.body.cabecera)), | |
| 49 | 46 | JSON.parse(JSON.stringify(req.body.cuerpo))); |
| 50 | 47 | |
| 51 | 48 | delete req.body.cabecera.idTransaccion; |
| ... | ... | @@ -54,15 +51,15 @@ router.post('/comprobante', function(req, res) { |
| 54 | 51 | delete req.body.cabecera.E_HD2; |
| 55 | 52 | |
| 56 | 53 | //smalldatetime |
| 57 | - req.body.cabecera.FEC = moment(req.body.cabecera.FEC).format('YYYY-MM-DD HH:mm:ss'); | |
| 58 | - req.body.cabecera.FECCAI = moment(req.body.cabecera.FECCAI).format('YYYY-MM-DD HH:mm:ss'); | |
| 59 | - req.body.cabecera.FECVEN = moment(req.body.cabecera.FECVEN).format('YYYY-MM-DD HH:mm:ss'); | |
| 60 | - | |
| 54 | + req.body.cabecera.FEC = new Date(req.body.cabecera.FEC).toISOString().slice(0, 19).replace('T', ' '); | |
| 55 | + req.body.cabecera.FECCAI = new Date(req.body.cabecera.FECCAI).toISOString().slice(0, 19).replace('T', ' '); | |
| 56 | + req.body.cabecera.FECVEN = new Date(req.body.cabecera.FECVEN).toISOString().slice(0, 19).replace('T', ' '); | |
| 61 | 57 | //datetime |
| 62 | 58 | req.body.cabecera.FEV = moment(req.body.cabecera.FEV).format('YYYYMMDD'); |
| 63 | 59 | req.body.cabecera.FEP = moment(req.body.cabecera.FEP).format('YYYYMMDD'); |
| 64 | 60 | |
| 65 | 61 | var promesas = [ |
| 62 | + recadv, | |
| 66 | 63 | knex('PMAEFACT').insert(req.body.cabecera), |
| 67 | 64 | knex('PCOBYPAG').insert({ |
| 68 | 65 | COD: req.body.cabecera.COD, |
| ... | ... | @@ -89,7 +86,7 @@ router.post('/comprobante', function(req, res) { |
| 89 | 86 | HOS: '', |
| 90 | 87 | E_HD: '', |
| 91 | 88 | C_HD: '' |
| 92 | - }) | |
| 89 | + }), | |
| 93 | 90 | ]; |
| 94 | 91 | |
| 95 | 92 | req.body.cuerpo.forEach(cuerpo => { |
watch/index.js
| ... | ... | @@ -2,7 +2,7 @@ module.exports = function (dir, callback) { |
| 2 | 2 | |
| 3 | 3 | const chokidar = require('chokidar'); |
| 4 | 4 | |
| 5 | - const watcher = chokidar.watch(dir, { ignored: config.dirDestino }); | |
| 5 | + const watcher = chokidar.watch(dir, { ignored: [config.dirDestino, config.dirRecadv] }); | |
| 6 | 6 | |
| 7 | 7 | watcher.on('add', function(file) { |
| 8 | 8 |