53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.listarVinculos = exports.tx_vinculos__listar = void 0;
|
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
const p_respostas_1 = require("p-respostas");
|
|
const node_cache_1 = require("./plugins/node-cache");
|
|
const uuid_1 = require("./plugins/uuid");
|
|
exports.tx_vinculos__listar = "vinculos__listar";
|
|
const listarVinculos = async ({ token, url_api_autenticacao, desativarCache, }) => {
|
|
debugger;
|
|
const chaveCache = (0, uuid_1.uuidV3)({ token, url_api_autenticacao });
|
|
// Buscar promeiro no cache
|
|
if (!desativarCache) {
|
|
const valorCache = node_cache_1.cacheAuDrive.get(chaveCache);
|
|
if (valorCache)
|
|
return valorCache;
|
|
}
|
|
const res = (async () => {
|
|
const url = `${url_api_autenticacao}/api/${exports.tx_vinculos__listar}`;
|
|
return (0, cross_fetch_1.default)(url, {
|
|
headers: { token, "Content-Type": "application/json" },
|
|
body: "{}",
|
|
method: "post",
|
|
})
|
|
.then(async (a) => {
|
|
const texto = await a.text();
|
|
try {
|
|
const res = JSON.parse(texto);
|
|
return res;
|
|
}
|
|
catch (error) {
|
|
return p_respostas_1.respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [texto, error]);
|
|
}
|
|
})
|
|
.catch((error) => p_respostas_1.respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
|
error,
|
|
]));
|
|
})();
|
|
node_cache_1.cacheAuDrive.set(chaveCache, res.then((a) => {
|
|
try {
|
|
if (a.eErro) {
|
|
node_cache_1.cacheAuDrive.del(chaveCache);
|
|
}
|
|
}
|
|
catch { }
|
|
return a;
|
|
}), 10);
|
|
return res;
|
|
};
|
|
exports.listarVinculos = listarVinculos;
|