build
This commit is contained in:
parent
a6205f1ab6
commit
e580643abc
40 changed files with 329 additions and 507 deletions
|
|
@ -3,26 +3,28 @@ import type { z } from "zod"
|
|||
import type { zAmbiente } from "../ts/ambiente"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
type tipoPostCodigoContaSite = { site: string }
|
||||
import node_fetch from "cross-fetch"
|
||||
|
||||
export const codigoContaSite = async ({
|
||||
ambiente,
|
||||
post,
|
||||
buscar,
|
||||
}: {
|
||||
ambiente: z.infer<typeof zAmbiente>
|
||||
post: tipoPostCodigoContaSite
|
||||
/** função que conecta com a API */
|
||||
buscar: (
|
||||
url: string,
|
||||
post: tipoPostCodigoContaSite,
|
||||
) => Promise<tipoResposta<string>>
|
||||
}): Promise<tipoResposta<string>> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/codigo_prefeitura_site`
|
||||
|
||||
try {
|
||||
const resp = await buscar(url, post).catch((e) =>
|
||||
respostaComuns.erro(`erro ao buscar código do site: ${e}`),
|
||||
)
|
||||
const resp = await node_fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(post),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro("Erro ao enviar registros", [e.message]),
|
||||
)
|
||||
.then((r) => r as tipoResposta<string>)
|
||||
|
||||
return resp
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
import type { z } from "zod"
|
||||
import type { zAmbiente } from "../ts/ambiente"
|
||||
|
|
@ -15,14 +16,9 @@ export type tipoUsuarioExterno = {
|
|||
export const usuarios_quipo_governo = async ({
|
||||
token_produto,
|
||||
ambiente,
|
||||
buscar,
|
||||
}: {
|
||||
ambiente: z.infer<typeof zAmbiente>
|
||||
token_produto: string
|
||||
buscar: (
|
||||
url: string,
|
||||
headers: { [k: string]: string },
|
||||
) => Promise<tipoResposta<tipoUsuarioExterno[]>>
|
||||
}): Promise<tipoResposta<tipoUsuarioExterno[]>> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/usuarios_quipo_governo`
|
||||
|
||||
|
|
@ -32,7 +28,12 @@ export const usuarios_quipo_governo = async ({
|
|||
token: token_produto,
|
||||
}
|
||||
|
||||
return buscar(url, headers).catch((e) =>
|
||||
respostaComuns.erro(`erro ao buscar usuários quipo governo: ${e}`),
|
||||
)
|
||||
return node_fetch(url, {
|
||||
headers,
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro("Erro ao buscar usuários quipo governo", [e.message]),
|
||||
)
|
||||
.then((r) => r as tipoResposta<tipoUsuarioExterno[]>)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { tipoResposta } from "p-respostas"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
type tipoPostValidarTokem = { token: string }
|
||||
import node_fetch from "cross-fetch"
|
||||
import type { z } from "zod"
|
||||
import type { zAmbiente } from "../ts/ambiente"
|
||||
|
||||
|
|
@ -8,20 +9,20 @@ import type { zAmbiente } from "../ts/ambiente"
|
|||
export const validarToken = async ({
|
||||
ambiente,
|
||||
post,
|
||||
buscar,
|
||||
}: {
|
||||
ambiente: z.infer<typeof zAmbiente>
|
||||
post: tipoPostValidarTokem
|
||||
/** função que conecta com a API */
|
||||
buscar: (
|
||||
url: string,
|
||||
post: tipoPostValidarTokem,
|
||||
) => Promise<tipoResposta<any>>
|
||||
}): Promise<"valido" | "erro"> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/validar_token`
|
||||
|
||||
try {
|
||||
const resposta = await buscar(url, post)
|
||||
const resposta = await node_fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(post),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((r) => r as tipoResposta<any>)
|
||||
.then((resposta) =>
|
||||
resposta.eCerto ? ("valido" as const) : ("erro" as const),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ export const z_tipo_coluna_base_dados = z.enum([
|
|||
"confirmacao",
|
||||
"lista_texto",
|
||||
"lista_numero",
|
||||
"data",
|
||||
"mes",
|
||||
])
|
||||
|
||||
export const tiposSeriesAgregacoes = z.enum(["contagem", "somatoria"])
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ import {
|
|||
zp_registrar_base_dados,
|
||||
} from "./enviar_registros"
|
||||
|
||||
import { serie_consultar, zp_serie_consultar } from "./serie_consultar"
|
||||
import { serie_registrar, zp_serie_registrar } from "./serie_registrar"
|
||||
import { serie_consultar, zp_serie_registrar } from "./serie_consultar"
|
||||
|
||||
export { tiposSeriesAgregacoes }
|
||||
|
||||
|
|
@ -17,11 +16,9 @@ export const pPilao = {
|
|||
enviar_registros,
|
||||
zp_enviar_registros,
|
||||
|
||||
serie_registrar,
|
||||
zp_serie_registrar,
|
||||
|
||||
serie_consultar,
|
||||
zp_serie_consultar,
|
||||
|
||||
zp_produto_conta,
|
||||
validarZ,
|
||||
|
|
|
|||
|
|
@ -8,23 +8,24 @@ import {
|
|||
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 zp_serie_registrar = z.object({
|
||||
tabela: z.string(),
|
||||
colanuEixoX: z.string(),
|
||||
colunaAgrupamento: z.string(),
|
||||
agregacao: tiposSeriesAgregacoes,
|
||||
})
|
||||
|
||||
export const serie_consultar = ({
|
||||
emDesenvolvimento,
|
||||
parametros: { identificador },
|
||||
cliente: { conta, produto },
|
||||
parametros: { agregacao, colanuEixoX, colunaAgrupamento, tabela },
|
||||
}: {
|
||||
emDesenvolvimento?: boolean | undefined | null
|
||||
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>
|
||||
parametros: z.infer<typeof zp_serie_consultar>
|
||||
parametros: z.infer<typeof zp_serie_registrar>
|
||||
}) => {
|
||||
const dados = async (): Promise<
|
||||
tipoResposta<{
|
||||
|
|
@ -42,7 +43,10 @@ export const serie_consultar = ({
|
|||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
identificador,
|
||||
agregacao,
|
||||
colanuEixoX,
|
||||
colunaAgrupamento,
|
||||
tabela,
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
|
|
@ -56,6 +60,15 @@ export const serie_consultar = ({
|
|||
}
|
||||
|
||||
const url = (): string => {
|
||||
const pr = {
|
||||
produto,
|
||||
conta,
|
||||
agregacao,
|
||||
colanuEixoX,
|
||||
colunaAgrupamento,
|
||||
tabela,
|
||||
}
|
||||
|
||||
const vUrl = new URL(
|
||||
`${
|
||||
emDesenvolvimento
|
||||
|
|
@ -64,9 +77,9 @@ export const serie_consultar = ({
|
|||
}${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}`,
|
||||
)
|
||||
|
||||
vUrl.searchParams.append("produto", produto)
|
||||
vUrl.searchParams.append("conta", conta)
|
||||
vUrl.searchParams.append("identificador", identificador)
|
||||
for (const [k, v] of Object.entries(pr)) {
|
||||
vUrl.searchParams.append(k, JSON.stringify(v))
|
||||
}
|
||||
|
||||
return vUrl.href
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
tiposSeriesAgregacoes,
|
||||
type zp_produto_conta,
|
||||
} from "./_variaveis"
|
||||
|
||||
//registrar serie
|
||||
|
||||
export const zp_serie_registrar = z.object({
|
||||
tabela: z.string(),
|
||||
identificador: z.string(),
|
||||
colanuEixoX: z.string(),
|
||||
colunaAgrupamento: z.string(),
|
||||
agregacao: tiposSeriesAgregacoes,
|
||||
})
|
||||
|
||||
export const serie_registrar = async ({
|
||||
emDesenvolvimento,
|
||||
cliente: { conta, produto },
|
||||
parametros: {
|
||||
agregacao,
|
||||
colanuEixoX,
|
||||
colunaAgrupamento,
|
||||
identificador,
|
||||
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_serie_registrar>
|
||||
}): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${`${PREFIXO}/${Object.keys({ serie_registrar })[0]}/${produto}/${conta}`}`,
|
||||
)
|
||||
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
tabela,
|
||||
agregacao,
|
||||
emDesenvolvimento,
|
||||
colanuEixoX,
|
||||
colunaAgrupamento,
|
||||
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<true>)
|
||||
|
||||
return resp
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue