melhorias de tipagem
This commit is contained in:
parent
1d5d3a48b4
commit
afa28a0699
32 changed files with 435 additions and 486 deletions
72
src/pilao-de-dados/_serie_consultar.ts
Normal file
72
src/pilao-de-dados/_serie_consultar.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
tiposSeriesAgregacoes,
|
||||
type zp_produto_conta,
|
||||
} from "./variaveis"
|
||||
|
||||
export const zp_serie_registrar = z.object({
|
||||
tabela: z.string(),
|
||||
colanuEixoX: z.string(),
|
||||
colunaAgrupamento: z.string().array().optional(),
|
||||
agregacao: tiposSeriesAgregacoes,
|
||||
})
|
||||
|
||||
export const serie_consultar =
|
||||
(cliente: z.infer<typeof zp_produto_conta>) =>
|
||||
(parametros: z.infer<typeof zp_serie_registrar>) => {
|
||||
const dados = async (): Promise<
|
||||
tipoResposta<{
|
||||
registros: any[]
|
||||
legenda: string
|
||||
serie: z.infer<typeof zp_serie_registrar>
|
||||
}>
|
||||
> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(cliente.emDesenvolvimento)}${`${PREFIXO}/${
|
||||
tiposSeriesAgregacoes.enum.contagem
|
||||
}/${cliente.produto}/${cliente.conta}`}`,
|
||||
)
|
||||
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro("Erro ao enviar registros", [e.message]),
|
||||
)
|
||||
.then((r) => r as tipoResposta<any>)
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
const url = (): string => {
|
||||
const pr = {
|
||||
cliente,
|
||||
parametros,
|
||||
}
|
||||
|
||||
const vUrl = new URL(
|
||||
`${
|
||||
cliente.emDesenvolvimento
|
||||
? "http://127.0.0.1:5081"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}`,
|
||||
)
|
||||
|
||||
const serie = encodeURIComponent(JSON.stringify(pr, null, 2))
|
||||
|
||||
return `${vUrl.href}?serie=${serie}`
|
||||
}
|
||||
|
||||
return {
|
||||
dados,
|
||||
url,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue