index.js
656 Bytes
module.exports = function(comprobante, nameFile) {
var promesas = [];
promesas.push(knex('PMAEFACT_TEMP').insert(comprobante.cabecera));
comprobante.cuerpo.forEach(cuerpo => {
promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo));
});
Promise.all(promesas).then(function() {
nameFileDest = nameFile.split('\\')[nameFile.split('\\').length - 1];
var pathDest = config.dirDestino + '/' + nameFileDest;
fs.rename(nameFile, pathDest, function(err) {
if(err) console.log(err);
console.log('COMPROBANTE GUARDADO CON ÉXITO');
});
}).catch(function() {
console.log('ERROR AL GUARDAR EL COMPROBANTE');
});
}