This commit is contained in:
Luiz H. R. Silva 2024-06-15 17:16:30 -03:00
parent 1a2cd2ce56
commit a435b0c6ae
17 changed files with 124 additions and 227 deletions

View file

@ -0,0 +1,81 @@
import type { tipoResposta } from "p-respostas"
import { respostaComuns } from "p-respostas"
import { z } from "zod"
import {
PREFIXO,
tiposSeriesAgregacoes,
type zp_produto_conta,
} from "./_variaveis"
import type { zp_serie_registrar } from "./serie_registrar"
//consultar compilação
export const zp_serie_consultar = z.object({
identificador: z.string(),
})
export const serie_consultar = ({
emDesenvolvimento,
parametros: { identificador },
cliente: { conta, produto },
}: {
emDesenvolvimento?: boolean | undefined | null
/** Identificação do cliente */
cliente: z.infer<typeof zp_produto_conta>
parametros: z.infer<typeof zp_serie_consultar>
}) => {
const dados = async (): Promise<
tipoResposta<{
registros: any[]
legenda: string
serie: z.infer<typeof zp_serie_registrar>
}>
> => {
const url = new URL(
`${
emDesenvolvimento
? "http://127.0.0.1:5080"
: "https://carro-de-boi.idz.one"
}${`${PREFIXO}/${
tiposSeriesAgregacoes.enum.contagem
}/${produto}/${conta}`}`,
)
const resp = await fetch(url.toString(), {
method: "POST",
body: JSON.stringify({
identificador,
}),
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 vUrl = new URL(
`${
emDesenvolvimento
? "http://127.0.0.1:5081"
: "https://carro-de-boi.idz.one"
}${PREFIXO}/grafico`,
)
vUrl.searchParams.append("produto", produto)
vUrl.searchParams.append("conta", conta)
vUrl.searchParams.append("identificador", identificador)
return vUrl.href
}
return {
dados,
url,
}
}