build
This commit is contained in:
parent
93d3caa378
commit
2cf1dfe75d
16 changed files with 149 additions and 201 deletions
|
|
@ -25,7 +25,8 @@ exports.zp_enviar_registros = zod_1.z.object({
|
|||
});
|
||||
class ClassPilaoEnviar {
|
||||
constructor({ conta, produto, emDesenvolvimento, ver_log, }) {
|
||||
this.__registros = [];
|
||||
this.__registrosParaEnvio = [];
|
||||
this.__codigosParaDeletar = [];
|
||||
this.__conta = conta;
|
||||
this.__produto = produto;
|
||||
this.__emDesenvolvimento = emDesenvolvimento;
|
||||
|
|
@ -35,12 +36,12 @@ class ClassPilaoEnviar {
|
|||
this.__tabela = tabela;
|
||||
return this;
|
||||
}
|
||||
adicionarRegistro(...registro) {
|
||||
this.__registros.push(...registro);
|
||||
adicionarRegistroParaEnviar(...registro) {
|
||||
this.__registrosParaEnvio.push(...registro);
|
||||
return this;
|
||||
}
|
||||
async enviar() {
|
||||
const registros = this.__registros;
|
||||
async __salvar_enviar_registros() {
|
||||
const registros = this.__registrosParaEnvio;
|
||||
const url = new URL(`${(0, variaveis_1.urlPilao)(this.__emDesenvolvimento).api}/enviar_registros/${this.__produto}/${this.__conta}`);
|
||||
if (this.__ver_log)
|
||||
console.log(`[PILÃO]: Enviando "${registros.length}" registros na tabela "${this.__tabela}" para "${url}".`);
|
||||
|
|
@ -63,6 +64,36 @@ class ClassPilaoEnviar {
|
|||
}
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
}
|
||||
async __salvar_deletar_registros() {
|
||||
const codigos = [...this.__codigosParaDeletar];
|
||||
const url = new URL(`${(0, variaveis_1.urlPilao)(this.__emDesenvolvimento).api}/deletar_registros/${this.__produto}/${this.__conta}`);
|
||||
const tamanhoBlocos = 1000;
|
||||
while (codigos.length > 0) {
|
||||
const bloco = codigos.splice(0, tamanhoBlocos);
|
||||
const resp = await (0, cross_fetch_1.default)(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela: this.__tabela, codigos: bloco }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]))
|
||||
.then((r) => r);
|
||||
if (resp.eErro) {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
this.__codigosParaDeletar;
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
}
|
||||
async salvar() {
|
||||
const re = await this.__salvar_enviar_registros();
|
||||
if (re.eErro)
|
||||
return re;
|
||||
const rd = await this.__salvar_deletar_registros();
|
||||
if (rd.eErro)
|
||||
return rd;
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
}
|
||||
}
|
||||
const PilaoEnviar = (_) => new ClassPilaoEnviar(_);
|
||||
exports.PilaoEnviar = PilaoEnviar;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue