This commit is contained in:
Luiz H. R. Silva 2024-06-14 13:50:29 -03:00
parent a566e000b7
commit d8a5a12387
4 changed files with 53 additions and 24 deletions

View file

@ -19,13 +19,20 @@ export const enviar_registros = ({ emDesenvolvimento, cliente: { conta, produto
const url = new URL(`${emDesenvolvimento
? "http://127.0.0.1:5080"
: "https://carro-de-boi.idz.one"}${PREFIXO}/enviar-registro/${produto}/${conta}`);
const resp = yield fetch(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela, registros }),
headers: { "Content-Type": "application/json" },
})
.then((r) => r.json())
.catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]))
.then((r) => r);
return resp;
const tamanhoBlocos = 1000;
while (registros.length > 0) {
const bloco = registros.splice(0, tamanhoBlocos);
const resp = yield fetch(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela, registros: bloco }),
headers: { "Content-Type": "application/json" },
})
.then((r) => r.json())
.catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]))
.then((r) => r);
if (resp.eErro) {
return resp;
}
}
return respostaComuns.valor(true);
});