refatoração
This commit is contained in:
parent
117bdbef7b
commit
8b8406e245
28 changed files with 300 additions and 51 deletions
|
|
@ -43,3 +43,6 @@ export const validarColuna = {
|
|||
lista_texto: z.array(z.string()).nullable(),
|
||||
lista_numero: z.array(z.number()).nullable(),
|
||||
}
|
||||
|
||||
export const baseUrlPilao = (emDesenvolvimento?: boolean | null | undefined) =>
|
||||
emDesenvolvimento ? "http://127.0.0.1:5080" : "https://carro-de-boi.idz.one"
|
||||
|
|
|
|||
52
src/pilao-de-dados/deletar_registros.ts
Normal file
52
src/pilao-de-dados/deletar_registros.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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 = async ({
|
||||
emDesenvolvimento,
|
||||
cliente: { conta, produto },
|
||||
parametros: { codigos, tabela },
|
||||
}: {
|
||||
emDesenvolvimento?: boolean | undefined | null
|
||||
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>
|
||||
/** Parametros da função */
|
||||
|
||||
parametros: 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 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)
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import { PREFIXO, type zp_produto_conta } from "./_variaveis"
|
||||
import { PREFIXO, baseUrlPilao, type zp_produto_conta } from "./_variaveis"
|
||||
|
||||
//enviar registros para base de dados
|
||||
export const zp_enviar_registros = z.object({
|
||||
|
|
@ -23,11 +23,9 @@ export const enviar_registros = async ({
|
|||
parametros: z.infer<typeof zp_enviar_registros>
|
||||
}): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${
|
||||
emDesenvolvimento
|
||||
? "http://127.0.0.1:5080"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}${PREFIXO}/enviar-registro/${produto}/${conta}`,
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${PREFIXO}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`,
|
||||
)
|
||||
|
||||
const tamanhoBlocos = 1000
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { tiposSeriesAgregacoes, validarZ, zp_produto_conta } from "./_variaveis"
|
||||
import { deletar_registros, zp_deletar_registros } from "./deletar_registros"
|
||||
import { enviar_registros, zp_enviar_registros } from "./enviar_registros"
|
||||
import {
|
||||
registrar_base_dados,
|
||||
|
|
@ -24,4 +25,7 @@ export const pPilao = {
|
|||
|
||||
zp_produto_conta,
|
||||
validarZ,
|
||||
|
||||
deletar_registros,
|
||||
zp_deletar_registros,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { respostaComuns } from "p-respostas"
|
|||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
tiposColunasBasedados,
|
||||
type zp_produto_conta,
|
||||
} from "./_variaveis"
|
||||
|
|
@ -31,11 +32,9 @@ export const registrar_base_dados = async ({
|
|||
parametros: z.infer<typeof zp_registrar_base_dados>
|
||||
}): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${
|
||||
emDesenvolvimento
|
||||
? "http://127.0.0.1:5080"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}${`${PREFIXO}/registar-base-dados/${produto}/${conta}`}`,
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${`${PREFIXO}/${Object.keys({ registrar_base_dados })[0]}/${produto}/${conta}`}`,
|
||||
)
|
||||
|
||||
const resp = await fetch(url.toString(), {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { respostaComuns } from "p-respostas"
|
|||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
tiposSeriesAgregacoes,
|
||||
type zp_produto_conta,
|
||||
} from "./_variaveis"
|
||||
|
|
@ -33,11 +34,7 @@ export const serie_consultar = ({
|
|||
}>
|
||||
> => {
|
||||
const url = new URL(
|
||||
`${
|
||||
emDesenvolvimento
|
||||
? "http://127.0.0.1:5080"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}${`${PREFIXO}/${
|
||||
`${baseUrlPilao(emDesenvolvimento)}${`${PREFIXO}/${
|
||||
tiposSeriesAgregacoes.enum.contagem
|
||||
}/${produto}/${conta}`}`,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { z } from "zod"
|
|||
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
tiposSeriesAgregacoes,
|
||||
type zp_produto_conta,
|
||||
} from "./_variaveis"
|
||||
|
|
@ -36,11 +37,9 @@ export const serie_registrar = async ({
|
|||
parametros: z.infer<typeof zp_serie_registrar>
|
||||
}): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${
|
||||
emDesenvolvimento
|
||||
? "http://127.0.0.1:5080"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}${`${PREFIXO}/registar-serie/${produto}/${conta}`}`,
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${`${PREFIXO}/${Object.keys({ serie_registrar })[0]}/${produto}/${conta}`}`,
|
||||
)
|
||||
|
||||
const resp = await fetch(url.toString(), {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue