Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Otimização para requisições assincronas.
Browse files Browse the repository at this point in the history
  • Loading branch information
lealhugui committed Jun 18, 2019
1 parent aea716b commit e8f1812
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-dfe",
"version": "0.0.14",
"version": "0.0.15",
"description": "Geração e integração de NF-e/NFC-e para node.js",
"main": "lib/index.js",
"scripts": {
Expand Down
22 changes: 17 additions & 5 deletions src/factory/processor/nfeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export class NFeProcessor {
};

try {
let retEnviNFe = null;

if (!nfeObj) {
let xmlObj = XmlHelper.deserializeXml(xmlLote, { explicitArray: false });
Expand All @@ -161,15 +162,26 @@ export class NFeProcessor {
this.configuraUrlsSefaz(modelo, ambiente);

let retornoEnvio = await this.enviarNF(xmlLote, this.empresa.certificado);
result.envioNF = retornoEnvio;

let retEnviNFe = Object(retornoEnvio.data).retEnviNFe;
if (retornoEnvio && retornoEnvio.data) {
const data = Object(retornoEnvio.data);
if (data.retEnviNFe) {
retEnviNFe = data.retEnviNFe;
}
} else {
throw new Error('Erro ao realizar requisição');
}

if (retEnviNFe.cStat == '104' && retEnviNFe.protNFe.infProt.cStat == '100') {
console.log('node-dfe------->: ', retEnviNFe.cStat);
console.log(retEnviNFe && retEnviNFe.cStat == '104' && retEnviNFe.protNFe.infProt.cStat == '100');
console.log(retEnviNFe && retEnviNFe.cStat == '103');

result.envioNF = retornoEnvio;

if (retEnviNFe && retEnviNFe.cStat == '104' && retEnviNFe.protNFe.infProt.cStat == '100') {
// retorno síncrono
result.success = true;

} else if (retEnviNFe.cStat == '103') {
} else if (retEnviNFe && retEnviNFe.cStat == '103') {
let recibo = retEnviNFe.infRec.nRec;
let xmlConRecNFe = this.gerarXmlConsultaProc(ambiente, recibo);

Expand Down

0 comments on commit e8f1812

Please sign in to comment.