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

@ -30,14 +30,25 @@ export const enviar_registros = async ({
}${PREFIXO}/enviar-registro/${produto}/${conta}`,
)
const resp = await 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 as tipoResposta<true>)
const tamanhoBlocos = 1000
return resp
while (registros.length > 0) {
const bloco = registros.splice(0, tamanhoBlocos)
const resp = await 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 as tipoResposta<true>)
if (resp.eErro) {
return resp
}
}
return respostaComuns.valor(true)
}