.
This commit is contained in:
parent
a566e000b7
commit
d8a5a12387
4 changed files with 53 additions and 24 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue