.
This commit is contained in:
parent
9f8aa2299a
commit
91952a6fa5
8 changed files with 420 additions and 3 deletions
123
dist-back/converter-resposta-e-licencie-para-p-resposta.js
Normal file
123
dist-back/converter-resposta-e-licencie-para-p-resposta.js
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var converter_resposta_e_licencie_para_p_resposta_exports = {};
|
||||
__export(converter_resposta_e_licencie_para_p_resposta_exports, {
|
||||
codigosErros: () => codigosErros,
|
||||
converterRespostaELicencieParaPResposta: () => converterRespostaELicencieParaPResposta
|
||||
});
|
||||
module.exports = __toCommonJS(converter_resposta_e_licencie_para_p_resposta_exports);
|
||||
var import_respostas = require("./respostas");
|
||||
const codigosErros = {
|
||||
400: "Erro de requisi\xE7\xE3o",
|
||||
403: "N\xE3o autenticado",
|
||||
500: "Erro interno",
|
||||
504: "Tempo de resposta excedido"
|
||||
};
|
||||
const mapaCodigoELicencieParaPResposta = {
|
||||
400: import_respostas.codigosResposta.erroConhecido,
|
||||
403: import_respostas.codigosResposta.erroPermissao,
|
||||
500: import_respostas.codigosResposta.erroDesconhecido,
|
||||
504: import_respostas.codigosResposta.tempoEsgotado
|
||||
};
|
||||
const mapaCodigoPRespostaParaELicencie = {
|
||||
[import_respostas.codigosResposta.erroConhecido]: 400,
|
||||
[import_respostas.codigosResposta.erroPermissao]: 403,
|
||||
[import_respostas.codigosResposta.erroDesconhecido]: 500,
|
||||
[import_respostas.codigosResposta.erroNaoEncontrado]: 400,
|
||||
[import_respostas.codigosResposta.tempoEsgotado]: 504
|
||||
};
|
||||
function eRespostaPadrao(entrada) {
|
||||
return "cod" in entrada;
|
||||
}
|
||||
function detalhesParaArray(detalhes) {
|
||||
if (!detalhes) return void 0;
|
||||
if (Array.isArray(detalhes)) return detalhes;
|
||||
const entries = Object.entries(detalhes);
|
||||
if (entries.length === 0) return void 0;
|
||||
return entries.map(([chave, valor]) => {
|
||||
const valorStr = typeof valor === "string" ? valor : JSON.stringify(valor);
|
||||
return `${chave}: ${valorStr}`;
|
||||
});
|
||||
}
|
||||
function montarRespostaDual(op) {
|
||||
const detalhesArray = detalhesParaArray(op.detalhesOriginal);
|
||||
const detalhesRecord = op.detalhesOriginal && !Array.isArray(op.detalhesOriginal) ? op.detalhesOriginal : void 0;
|
||||
return {
|
||||
// P-Resposta
|
||||
cod: op.cod,
|
||||
valor: op.valor,
|
||||
mensagem: op.mensagem,
|
||||
eErro: op.eErro,
|
||||
eCerto: !op.eErro,
|
||||
detalhes: detalhesArray,
|
||||
// ELicencie (runtime)
|
||||
codigo: op.codigoELicencie,
|
||||
erro: op.erroELicencie,
|
||||
...detalhesRecord ? { detalhes: detalhesRecord } : {}
|
||||
};
|
||||
}
|
||||
const converterRespostaELicencieParaPResposta = (entrada) => {
|
||||
if (eRespostaPadrao(entrada)) {
|
||||
if (!entrada.eErro) {
|
||||
return montarRespostaDual({
|
||||
cod: import_respostas.codigosResposta.sucesso,
|
||||
valor: entrada.valor,
|
||||
mensagem: void 0,
|
||||
eErro: false,
|
||||
codigoELicencie: 200,
|
||||
erroELicencie: void 0,
|
||||
detalhesOriginal: entrada.detalhes
|
||||
});
|
||||
}
|
||||
return montarRespostaDual({
|
||||
cod: entrada.cod,
|
||||
valor: void 0,
|
||||
mensagem: entrada.mensagem,
|
||||
eErro: true,
|
||||
codigoELicencie: mapaCodigoPRespostaParaELicencie[entrada.cod],
|
||||
erroELicencie: entrada.mensagem,
|
||||
detalhesOriginal: entrada.detalhes
|
||||
});
|
||||
}
|
||||
if (!entrada.eErro) {
|
||||
return montarRespostaDual({
|
||||
cod: import_respostas.codigosResposta.sucesso,
|
||||
valor: entrada.valor,
|
||||
mensagem: void 0,
|
||||
eErro: false,
|
||||
codigoELicencie: entrada.codigo,
|
||||
erroELicencie: void 0,
|
||||
detalhesOriginal: entrada.detalhes
|
||||
});
|
||||
}
|
||||
return montarRespostaDual({
|
||||
cod: mapaCodigoELicencieParaPResposta[entrada.codigo],
|
||||
valor: void 0,
|
||||
mensagem: entrada.erro,
|
||||
eErro: true,
|
||||
codigoELicencie: entrada.codigo,
|
||||
erroELicencie: entrada.erro,
|
||||
detalhesOriginal: entrada.detalhes
|
||||
});
|
||||
};
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
codigosErros,
|
||||
converterRespostaELicencieParaPResposta
|
||||
});
|
||||
|
|
@ -15,8 +15,10 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var index_exports = {};
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
__reExport(index_exports, require("./converter-resposta-e-licencie-para-p-resposta"), module.exports);
|
||||
__reExport(index_exports, require("./respostas"), module.exports);
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
...require("./converter-resposta-e-licencie-para-p-resposta"),
|
||||
...require("./respostas")
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue