melhorias de tipagem
This commit is contained in:
parent
1d5d3a48b4
commit
afa28a0699
32 changed files with 435 additions and 486 deletions
44
src/pilao-de-dados/_deletar_registros.ts
Normal file
44
src/pilao-de-dados/_deletar_registros.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import { PREFIXO, baseUrlPilao, type zp_produto_conta } from "./variaveis"
|
||||
//enviar registros para base de dados
|
||||
export const zp_deletar_registros = z.object({
|
||||
tabela: z.string(),
|
||||
codigos: z.array(z.string()),
|
||||
})
|
||||
|
||||
export const deletar_registros =
|
||||
({ conta, produto, emDesenvolvimento }: z.infer<typeof zp_produto_conta>) =>
|
||||
async ({
|
||||
codigos,
|
||||
tabela,
|
||||
}: z.infer<typeof zp_deletar_registros>): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${PREFIXO}/${Object.keys({ deletar_registros })[0]}/${produto}/${conta}`,
|
||||
)
|
||||
const tamanhoBlocos = 1000
|
||||
|
||||
while (codigos.length > 0) {
|
||||
const bloco = codigos.splice(0, tamanhoBlocos)
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela, codigos: 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