remoção de pilão
This commit is contained in:
parent
f7a936e8dd
commit
02f9f3902b
21 changed files with 7 additions and 2641 deletions
|
|
@ -1,4 +1,3 @@
|
|||
export * from "./pilao-de-dados"
|
||||
export * from "./residuos"
|
||||
export * from "./NPS"
|
||||
export * from "./variaveis"
|
||||
|
|
|
|||
|
|
@ -1,311 +0,0 @@
|
|||
/** Drive completo do piilão de dados */
|
||||
|
||||
import crossFetch from "cross-fetch"
|
||||
import { nomeVariavel } from "p-comuns"
|
||||
|
||||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
import type { z } from "zod"
|
||||
|
||||
import type { zp_enviar_registros } from "../_enviar_registros"
|
||||
import { PREFIXO_PILAO, type zp_deletar_registros } from "../variaveis"
|
||||
|
||||
import type { visoes_pilao, z_padroes } from "../visoes/listaDeVisoes"
|
||||
import type { tipo_pilao_api } from "./pilao-api.ts"
|
||||
import type { tipoConstrutorPilao, tipoRetornoSerieconsulta } from "./tipagem"
|
||||
|
||||
export enum pilao_enderecos {
|
||||
"enviar-registros" = "enviar-registros",
|
||||
"deletar-registros" = "deletar-registros",
|
||||
"consultar-serie" = "consultar-serie",
|
||||
laboratório = "laboratório",
|
||||
}
|
||||
|
||||
export type nomesVisoes = keyof typeof visoes_pilao
|
||||
|
||||
export type retornoSerieConsultar<T extends nomesVisoes> = {
|
||||
dados: () => Promise<tipoResposta<tipoRetornoSerieconsulta<T>>>
|
||||
url: () => string
|
||||
}
|
||||
|
||||
export class ClassPilao {
|
||||
#produto: string
|
||||
#conta: string
|
||||
#emDesenvolvimento: boolean
|
||||
#ver_log: boolean
|
||||
#registrosParaEnvio: Record<
|
||||
string,
|
||||
z.infer<typeof zp_enviar_registros>["registros"]
|
||||
> = {}
|
||||
#codigosParaDeletar: Record<
|
||||
string,
|
||||
z.infer<typeof zp_deletar_registros>["codigos"]
|
||||
> = {}
|
||||
|
||||
constructor({
|
||||
conta,
|
||||
produto,
|
||||
emDesenvolvimento = false,
|
||||
ver_log = false,
|
||||
}: tipoConstrutorPilao & { ver_log?: boolean; emDesenvolvimento?: boolean }) {
|
||||
this.#produto = produto
|
||||
this.#conta = conta
|
||||
this.#emDesenvolvimento = emDesenvolvimento
|
||||
this.#ver_log = ver_log
|
||||
}
|
||||
|
||||
#gerarUrlApi(acao: string): { rota: string; url: URL } {
|
||||
const rota = `${PREFIXO_PILAO}/api/${acao}/${this.#produto}/${this.#conta}`
|
||||
const url = new URL(`${this.baseUrlApi}${rota}`)
|
||||
return { rota, url }
|
||||
}
|
||||
|
||||
#gerarUrlDrive(acao: string): { rota: string; url: URL } {
|
||||
const rota = `${PREFIXO_PILAO}/${acao}/${this.#produto}/${this.#conta}`
|
||||
const url = new URL(`${this.baseUrlApi}${rota}`)
|
||||
return { rota, url }
|
||||
}
|
||||
|
||||
rotaEnviarRegistros() {
|
||||
return this.#gerarUrlDrive(pilao_enderecos["enviar-registros"])
|
||||
}
|
||||
|
||||
rotaDeletarRegistro() {
|
||||
return this.#gerarUrlDrive(pilao_enderecos["deletar-registros"])
|
||||
}
|
||||
|
||||
rotaConsultarSerie() {
|
||||
return this.#gerarUrlDrive(pilao_enderecos["consultar-serie"])
|
||||
}
|
||||
|
||||
rotaIframeSerie(tipoVisao: nomesVisoes | ":tipoVisao") {
|
||||
const rota = `${PREFIXO_PILAO}/${pilao_enderecos["consultar-serie"]}/${this.#produto}/${this.#conta}/${tipoVisao}`
|
||||
const url = `${this.baseUrlSite}${rota}`
|
||||
return { rota, url }
|
||||
}
|
||||
|
||||
rotaFuncaoApi(funcao: keyof tipo_pilao_api | ":funcao") {
|
||||
return this.#gerarUrlApi(funcao)
|
||||
}
|
||||
|
||||
async consultarApi<T extends keyof tipo_pilao_api>(
|
||||
funcao: T,
|
||||
parametros: tipo_pilao_api[T]["pr"],
|
||||
): Promise<tipoResposta<tipo_pilao_api[T]["rs"]>> {
|
||||
try {
|
||||
const response = await crossFetch(this.rotaFuncaoApi(funcao).url, {
|
||||
body: JSON.stringify(parametros),
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
|
||||
const texto = await response.text()
|
||||
|
||||
try {
|
||||
const json = JSON.parse(texto)
|
||||
return json
|
||||
} catch {
|
||||
return respostaComuns.erro("Consulta não retornou json válido", [texto])
|
||||
}
|
||||
} catch (erro) {
|
||||
console.error(erro)
|
||||
return respostaComuns.erroInterno({
|
||||
erro,
|
||||
local: nomeVariavel({ ClassPilao }),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
get baseUrlApi() {
|
||||
return this.#emDesenvolvimento
|
||||
? "http://localhost:5080"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}
|
||||
|
||||
get baseUrlSite() {
|
||||
return this.#emDesenvolvimento
|
||||
? "http://localhost:5081"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}
|
||||
|
||||
validarCliente(_: any): tipoResposta<tipoConstrutorPilao> {
|
||||
if (!_?.conta) return respostaComuns.erro("Conta não informada")
|
||||
if (!_?.produto) return respostaComuns.erro("Produto não informado")
|
||||
return respostaComuns.valor(_)
|
||||
}
|
||||
|
||||
adicionarRegistroParaEnviar(
|
||||
tabela: string,
|
||||
...registros: z.infer<typeof zp_enviar_registros>["registros"]
|
||||
) {
|
||||
this.#registrosParaEnvio[tabela] = [
|
||||
...(this.#registrosParaEnvio[tabela] || []),
|
||||
...registros,
|
||||
]
|
||||
return this
|
||||
}
|
||||
|
||||
adicionarCodigoParaDeletar(
|
||||
tabela: string,
|
||||
...codigos: z.infer<typeof zp_deletar_registros>["codigos"]
|
||||
) {
|
||||
this.#codigosParaDeletar[tabela] = [
|
||||
...(this.#codigosParaDeletar[tabela] || []),
|
||||
...codigos,
|
||||
]
|
||||
return this
|
||||
}
|
||||
|
||||
private async processarRegistros(
|
||||
url: string,
|
||||
registros: any[],
|
||||
tabela: string,
|
||||
acao: string,
|
||||
): Promise<tipoResposta<true>> {
|
||||
const tamanhoBlocos = 1000
|
||||
while (registros.length > 0) {
|
||||
const bloco = registros
|
||||
.splice(0, tamanhoBlocos)
|
||||
.map((r) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(r).map(([k, v]) => [k, v === undefined ? null : v]),
|
||||
),
|
||||
)
|
||||
const resp = await crossFetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela, registros: bloco }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then(async (r) => {
|
||||
const texto = await r.text()
|
||||
try {
|
||||
const json = JSON.parse(texto)
|
||||
return json
|
||||
} catch {
|
||||
return respostaComuns.erro("Consulta não retornou json válido", [
|
||||
texto,
|
||||
])
|
||||
}
|
||||
})
|
||||
.catch((e) =>
|
||||
respostaComuns.erro(`Erro ao ${acao} registros`, [e.message]),
|
||||
)
|
||||
|
||||
if (resp.eErro) return resp
|
||||
}
|
||||
return respostaComuns.valor(true)
|
||||
}
|
||||
|
||||
async #salvarEnviarRegistros(): Promise<tipoResposta<true>> {
|
||||
for (const tabela of Object.keys(this.#registrosParaEnvio)) {
|
||||
const registros = this.#registrosParaEnvio[tabela] || []
|
||||
const url = this.rotaEnviarRegistros().url
|
||||
if (this.#ver_log)
|
||||
console.log(
|
||||
`[PILÃO]: Enviando ${registros.length} registros na tabela "${tabela}" para "${url}".`,
|
||||
)
|
||||
const resp = await this.processarRegistros(
|
||||
url.href,
|
||||
registros,
|
||||
tabela,
|
||||
"enviar",
|
||||
)
|
||||
if (resp.eErro) return resp
|
||||
this.#registrosParaEnvio[tabela] = []
|
||||
}
|
||||
return respostaComuns.valor(true)
|
||||
}
|
||||
|
||||
async #salvarDeletarRegistros(): Promise<tipoResposta<true>> {
|
||||
for (const tabela of Object.keys(this.#codigosParaDeletar)) {
|
||||
const codigos = [...(this.#codigosParaDeletar[tabela] || [])]
|
||||
const url = this.rotaDeletarRegistro().url
|
||||
const resp = await this.processarRegistros(
|
||||
url.href,
|
||||
codigos,
|
||||
tabela,
|
||||
"deletar",
|
||||
)
|
||||
if (resp.eErro) return resp
|
||||
}
|
||||
return respostaComuns.valor(true)
|
||||
}
|
||||
|
||||
async enviarRegistros(): Promise<tipoResposta<true>> {
|
||||
const re = await this.#salvarEnviarRegistros()
|
||||
if (re.eErro) return re
|
||||
const rd = await this.#salvarDeletarRegistros()
|
||||
if (rd.eErro) return rd
|
||||
return respostaComuns.valor(true)
|
||||
}
|
||||
|
||||
serieConsultar<T extends nomesVisoes>(
|
||||
tipoVisao: T,
|
||||
parametros_: z.infer<(typeof visoes_pilao)[T]> & z.infer<typeof z_padroes>,
|
||||
padroes?: Pick<z.infer<typeof z_padroes>, "descricao_pelo_usuario">,
|
||||
): retornoSerieConsultar<T> {
|
||||
const parametros = {
|
||||
...parametros_,
|
||||
...Object.fromEntries(
|
||||
Object.entries(padroes || {}).filter(([_, v]) => v !== undefined),
|
||||
),
|
||||
}
|
||||
|
||||
const dados = async (): Promise<
|
||||
tipoResposta<tipoRetornoSerieconsulta<T>>
|
||||
> => {
|
||||
const url = this.rotaConsultarSerie().url
|
||||
url.searchParams.set("visao", tipoVisao)
|
||||
const resp = await crossFetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then(async (r) => {
|
||||
const texto = await r.text()
|
||||
|
||||
try {
|
||||
const json = JSON.parse(texto)
|
||||
return json
|
||||
} catch {
|
||||
return respostaComuns.erro("Consulta não retornou json válido", [
|
||||
texto,
|
||||
])
|
||||
}
|
||||
})
|
||||
.catch((e) =>
|
||||
respostaComuns.erro("Erro ao enviar registros", [e.message]),
|
||||
)
|
||||
|
||||
if (this.#ver_log)
|
||||
console.log(
|
||||
`[PILÃO]: buscar dados de "${JSON.stringify(parametros)}" para "${url}".`,
|
||||
)
|
||||
return resp
|
||||
}
|
||||
|
||||
const url = (): string => {
|
||||
const vUrl = this.rotaIframeSerie(tipoVisao).url
|
||||
const serie = encodeURIComponent(JSON.stringify(parametros, null, 2))
|
||||
if (this.#ver_log)
|
||||
console.log(
|
||||
`[PILÃO]: Serie Consultar url de "${JSON.stringify(serie)}" para "${vUrl}".`,
|
||||
)
|
||||
return `${vUrl}?serie=${serie}`
|
||||
}
|
||||
|
||||
return {
|
||||
dados,
|
||||
url,
|
||||
}
|
||||
}
|
||||
|
||||
urlLaboratorio() {
|
||||
const rota = `${PREFIXO_PILAO}/${pilao_enderecos}/${this.#produto}/${this.#conta}`
|
||||
const url = `${this.baseUrlSite}${rota}`
|
||||
return { rota, url }
|
||||
}
|
||||
}
|
||||
|
||||
export const Pilao = (
|
||||
_: tipoConstrutorPilao & { ver_log?: boolean; emDesenvolvimento?: boolean },
|
||||
) => new ClassPilao(_)
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
import type { z } from "zod"
|
||||
import type { zp_registrar_base_dados } from "../_enviar_registros"
|
||||
|
||||
/**
|
||||
* {
|
||||
* 'rota':{
|
||||
* pr:{}// paramentros de entrada
|
||||
* rs:{}// resposta
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export type tipo_pilao_api = {
|
||||
/** retorna da data e hora do servido em formato iso */
|
||||
estado_servidor: {
|
||||
pr: {}
|
||||
rs: {
|
||||
data_hora: string
|
||||
}
|
||||
}
|
||||
tabelas: {
|
||||
pr: {}
|
||||
rs: z.infer<typeof zp_registrar_base_dados>[]
|
||||
}
|
||||
|
||||
unicos: {
|
||||
pr: {
|
||||
tabela: string
|
||||
coluna: string
|
||||
}
|
||||
rs: any[]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
import type { z } from "zod"
|
||||
import type { visoes_pilao, z_padroes } from "../visoes/listaDeVisoes"
|
||||
|
||||
export type tipoConstrutorPilao = { produto: string; conta: string }
|
||||
|
||||
export type z_tipagem_registros = {
|
||||
z_contagem_em_barra_vertical: { contagem: number; [k: string]: any }[]
|
||||
z_contagem_em_pizza: { contagem: number; [k: string]: any }[]
|
||||
z_tabela: { [k: string]: any }[]
|
||||
z_soma_em_barra_vertical: { soma: number; [k: string]: any }[]
|
||||
z_porcentagem_soma_em_barra_vertical: {
|
||||
porcentagem: number
|
||||
[k: string]: any
|
||||
}[]
|
||||
}
|
||||
|
||||
export type tipoRetornoSerieconsulta<T extends keyof typeof visoes_pilao> = {
|
||||
registros: z_tipagem_registros[T]
|
||||
legenda: string
|
||||
serie: z.infer<(typeof visoes_pilao)[T]> & z.infer<typeof z_padroes>
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
import { z } from "zod"
|
||||
import { z_tipos_dados_registro } from "./variaveis"
|
||||
|
||||
export const zp_registrar_base_dados = z.object({
|
||||
tabela: z.string(),
|
||||
colunas: z.array(
|
||||
z.object({
|
||||
coluna: z.string(),
|
||||
tipo: z_tipos_dados_registro,
|
||||
}),
|
||||
),
|
||||
})
|
||||
|
||||
//enviar registros para base de dados
|
||||
export const zp_enviar_registros = z.object({
|
||||
tabela: z.string(),
|
||||
registros: z.array(
|
||||
z.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
valor: z.any(),
|
||||
tipo: z_tipos_dados_registro.optional().nullable(),
|
||||
}),
|
||||
),
|
||||
),
|
||||
})
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { z } from "zod"
|
||||
import { operadores_pilao } from "./variaveis"
|
||||
|
||||
export const z_filtro = z.object({
|
||||
coluna: z.string(),
|
||||
valor: z.any(),
|
||||
operador: operadores_pilao,
|
||||
})
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
export { PREFIXO_PILAO, urlPilao } from "./variaveis"
|
||||
import {
|
||||
zp_enviar_registros,
|
||||
zp_registrar_base_dados,
|
||||
} from "./_enviar_registros"
|
||||
import {
|
||||
operadores_permitidos_por_tipo,
|
||||
operadores_pilao,
|
||||
validarZ,
|
||||
z_tipos_dados_registro,
|
||||
zp_deletar_registros,
|
||||
zp_produto_conta,
|
||||
} from "./variaveis"
|
||||
|
||||
export * from "./Pilao"
|
||||
export * from "./Pilao/pilao-api"
|
||||
export * from "./Pilao/tipagem"
|
||||
|
||||
import { pilao_enderecos } from "./Pilao"
|
||||
import { z_filtro } from "./_serie_consultar"
|
||||
import { extruturas_de_campos } from "./visoes"
|
||||
import { visoes_pilao, z_padroes } from "./visoes/listaDeVisoes"
|
||||
|
||||
export const pPilao = {
|
||||
zp_deletar_registros,
|
||||
zp_registrar_base_dados,
|
||||
z_tipos_dados_registro,
|
||||
zp_enviar_registros,
|
||||
|
||||
zp_produto_conta,
|
||||
validarZ,
|
||||
|
||||
operadores_pilao,
|
||||
operadores_permitidos_por_tipo,
|
||||
z_filtro,
|
||||
visoes_pilao,
|
||||
...visoes_pilao,
|
||||
extruturas_de_campos,
|
||||
z_padroes,
|
||||
pilao_enderecos,
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
|
||||
export const zp_deletar_registros = z.object({
|
||||
tabela: z.string(),
|
||||
codigos: z.array(z.string()),
|
||||
})
|
||||
|
||||
export const zAmbiente = z.enum(["desenvolvimento", "producao"])
|
||||
|
||||
export const PREFIXO_PILAO = "/pilao-de-dados"
|
||||
|
||||
export const validarZ = <T>(
|
||||
zodType: z.ZodType<T, any>,
|
||||
objeto: any,
|
||||
mensagem: string,
|
||||
) => {
|
||||
const validar = zodType.safeParse(objeto)
|
||||
if (!validar.success) {
|
||||
return respostaComuns.erro(
|
||||
mensagem,
|
||||
validar.error.errors.map((e) => `${e.path} ${e.message}`),
|
||||
)
|
||||
}
|
||||
return respostaComuns.valor(validar.data)
|
||||
}
|
||||
|
||||
export const zp_produto_conta = z.object({
|
||||
produto: z.string(),
|
||||
conta: z.string(),
|
||||
emDesenvolvimento: z.boolean().optional(),
|
||||
ver_log: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const z_tipos_dados_registro = z.enum([
|
||||
"texto",
|
||||
"numero",
|
||||
"confirmacao",
|
||||
"lista_texto",
|
||||
"lista_numero",
|
||||
"lista_mes",
|
||||
"lista_data",
|
||||
"mes",
|
||||
"data",
|
||||
])
|
||||
|
||||
export const operadores_pilao = z.enum(["=", "!=", ">", "<", ">=", "<=", "∩"])
|
||||
|
||||
export const operadores_permitidos_por_tipo: {
|
||||
[key in z.infer<typeof z_tipos_dados_registro>]: z.infer<
|
||||
typeof operadores_pilao
|
||||
>[]
|
||||
} = {
|
||||
confirmacao: ["=", "!="],
|
||||
data: ["=", "!=", ">", "<", ">=", "<="],
|
||||
lista_numero: ["∩"],
|
||||
lista_texto: ["∩"],
|
||||
lista_mes: ["∩"],
|
||||
lista_data: ["∩"],
|
||||
mes: ["=", "!=", ">", "<", ">=", "<="],
|
||||
numero: ["=", "!=", ">", "<", ">=", "<="],
|
||||
texto: ["=", "!="],
|
||||
}
|
||||
|
||||
export const z_validar_colunna_base_dados = {
|
||||
texto: z.string().nullable(),
|
||||
numero: z.number().nullable(),
|
||||
confirmacao: z.boolean().nullable(),
|
||||
lista_texto: z.array(z.string()).nullable(),
|
||||
lista_numero: z.array(z.number()).nullable(),
|
||||
}
|
||||
|
||||
export const urlPilao = (emDesenvolvimento?: boolean | null | undefined) => ({
|
||||
api:
|
||||
(emDesenvolvimento
|
||||
? "http://127.0.0.1:5080"
|
||||
: "https://carro-de-boi.idz.one") + PREFIXO_PILAO,
|
||||
|
||||
site:
|
||||
(emDesenvolvimento
|
||||
? "http://127.0.0.1:5081"
|
||||
: "https://carro-de-boi.idz.one") + PREFIXO_PILAO,
|
||||
})
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import type { visoes_pilao } from "../listaDeVisoes"
|
||||
import type { tipo_estrutura_visao_grafico } from "../tipagem"
|
||||
import { z_contagem_em_barra_vertical } from "./z_contagem_em_barra_vertical"
|
||||
import { z_contagem_em_pizza } from "./z_contagem_em_pizza"
|
||||
import { z_soma_em_barra_vertical } from "./z_soma_em_barra_vertical"
|
||||
import { z_tabela } from "./z_tabela"
|
||||
|
||||
/** Cria a estrutura de campos para insersão de dados */
|
||||
export const extruturas_de_campos: {
|
||||
[T in keyof typeof visoes_pilao]: tipo_estrutura_visao_grafico<T>
|
||||
} = {
|
||||
z_contagem_em_barra_vertical,
|
||||
z_contagem_em_pizza,
|
||||
z_soma_em_barra_vertical,
|
||||
z_tabela,
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// usar describe para definir o tipo de campo para render do componente
|
||||
|
||||
import type { tipo_estrutura_visao_grafico } from "../tipagem"
|
||||
|
||||
/** Cria a estrutura de campos para insersão de dados */
|
||||
export const z_contagem_em_barra_vertical: tipo_estrutura_visao_grafico<"z_contagem_em_barra_vertical"> =
|
||||
{
|
||||
visao: "z_contagem_em_barra_vertical",
|
||||
rotulo: "Contagem em Barra Vertical",
|
||||
tabela: ({ tabela }) => tabela,
|
||||
descricao: ({
|
||||
tabela,
|
||||
descricao_pelo_usuario,
|
||||
colanuEixoX,
|
||||
filtros,
|
||||
colunaAgrupamento,
|
||||
}) => {
|
||||
if (String(descricao_pelo_usuario || "").trim())
|
||||
return String(descricao_pelo_usuario || "").trim()
|
||||
|
||||
return `Contagem de ${tabela} por ${colanuEixoX}${
|
||||
!filtros?.length
|
||||
? ""
|
||||
: `, quando ${filtros
|
||||
.map(
|
||||
({ coluna, operador, valor }) =>
|
||||
`${coluna} ${operador} ${valor}`,
|
||||
)
|
||||
.join(", ")}`
|
||||
}${
|
||||
!colunaAgrupamento?.length
|
||||
? ""
|
||||
: `, agrupado por ${colunaAgrupamento.join(", ")}`
|
||||
}.`
|
||||
},
|
||||
campos: {
|
||||
tabela: { rotulo: "Tabela", tipo_campo: "tabela", order: 1 },
|
||||
|
||||
colanuEixoX: {
|
||||
rotulo: "Coluna do Eixo X",
|
||||
tipo_campo: "coluna",
|
||||
order: 2,
|
||||
},
|
||||
colunaAgrupamento: {
|
||||
rotulo: "Colunas de Agrupamento",
|
||||
tipo_campo: "lista_colunas",
|
||||
order: 3,
|
||||
},
|
||||
descricao_pelo_usuario: {
|
||||
rotulo: "Descrição (opcional)",
|
||||
tipo_campo: "texto",
|
||||
order: 4,
|
||||
},
|
||||
filtros: { rotulo: "Filtros", tipo_campo: "lista_filtros", order: 5 },
|
||||
},
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
// usar describe para definir o tipo de campo para render do componente
|
||||
|
||||
import type { tipo_estrutura_visao_grafico } from "../tipagem"
|
||||
|
||||
/** Cria a estrutura de campos para insersão de dados */
|
||||
export const z_contagem_em_pizza: tipo_estrutura_visao_grafico<"z_contagem_em_pizza"> =
|
||||
{
|
||||
visao: "z_contagem_em_pizza",
|
||||
rotulo: "Contagem em Pizza",
|
||||
tabela: ({ tabela }) => tabela,
|
||||
descricao: ({ tabela, descricao_pelo_usuario, classes, filtros }) => {
|
||||
if (String(descricao_pelo_usuario || "").trim())
|
||||
return String(descricao_pelo_usuario || "").trim()
|
||||
|
||||
return `Contagem de ${tabela} por ${classes}${
|
||||
!filtros?.length
|
||||
? ""
|
||||
: `, quando ${filtros
|
||||
.map(
|
||||
({ coluna, operador, valor }) =>
|
||||
`${coluna} ${operador} ${valor}`,
|
||||
)
|
||||
.join(", ")}`
|
||||
}.`
|
||||
},
|
||||
campos: {
|
||||
tabela: { rotulo: "Tabela", tipo_campo: "tabela", order: 1 },
|
||||
classes: { rotulo: "Classes", tipo_campo: "coluna", order: 2 },
|
||||
descricao_pelo_usuario: {
|
||||
rotulo: "Descrição (opcional)",
|
||||
tipo_campo: "texto",
|
||||
order: 3,
|
||||
},
|
||||
filtros: { rotulo: "Filtros", tipo_campo: "lista_filtros", order: 4 },
|
||||
},
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
// usar describe para definir o tipo de campo para render do componente
|
||||
|
||||
import type { tipo_estrutura_visao_grafico } from "../tipagem"
|
||||
|
||||
/** Cria a estrutura de campos para insersão de dados */
|
||||
export const z_soma_em_barra_vertical: tipo_estrutura_visao_grafico<"z_soma_em_barra_vertical"> =
|
||||
{
|
||||
visao: "z_soma_em_barra_vertical",
|
||||
rotulo: "Soma em Barra Vertical",
|
||||
tabela: ({ tabela }) => tabela,
|
||||
descricao: ({
|
||||
descricao_pelo_usuario,
|
||||
colanuEixoX,
|
||||
filtros,
|
||||
colunaAgrupamento,
|
||||
colunaSoma,
|
||||
exibirComoPorcentagem,
|
||||
}) => {
|
||||
if (String(descricao_pelo_usuario || "").trim())
|
||||
return String(descricao_pelo_usuario || "").trim()
|
||||
|
||||
return `${exibirComoPorcentagem ? "Porcentagem " : "Soma"} de ${colunaSoma} por ${colanuEixoX}${
|
||||
!filtros?.length
|
||||
? ""
|
||||
: `, quando ${filtros
|
||||
.map(
|
||||
({ coluna, operador, valor }) =>
|
||||
`${coluna} ${operador} ${valor}`,
|
||||
)
|
||||
.join(", ")}`
|
||||
}${
|
||||
!colunaAgrupamento?.length
|
||||
? ""
|
||||
: `, agrupado por ${colunaAgrupamento.join(", ")}`
|
||||
}.`
|
||||
},
|
||||
campos: {
|
||||
tabela: { rotulo: "Tabela", tipo_campo: "tabela", order: 1 },
|
||||
|
||||
colunaSoma: {
|
||||
rotulo: "Coluna de Somatória",
|
||||
tipo_campo: "coluna",
|
||||
order: 2,
|
||||
},
|
||||
|
||||
unidadeSoma: {
|
||||
rotulo: "Unidade de Somatória",
|
||||
tipo_campo: "texto",
|
||||
order: 3,
|
||||
},
|
||||
|
||||
colanuEixoX: {
|
||||
rotulo: "Coluna do Eixo X",
|
||||
tipo_campo: "coluna",
|
||||
order: 4,
|
||||
},
|
||||
colunaAgrupamento: {
|
||||
rotulo: "Colunas de Agrupamento",
|
||||
tipo_campo: "lista_colunas",
|
||||
order: 5,
|
||||
},
|
||||
descricao_pelo_usuario: {
|
||||
rotulo: "Descrição (opcional)",
|
||||
tipo_campo: "texto",
|
||||
order: 6,
|
||||
},
|
||||
exibirComoPorcentagem: {
|
||||
rotulo: "Exibir como porcentagem",
|
||||
order: 7,
|
||||
tipo_campo: "booleana",
|
||||
},
|
||||
filtros: { rotulo: "Filtros", tipo_campo: "lista_filtros", order: 8 },
|
||||
},
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// usar describe para definir o tipo de campo para render do componente
|
||||
|
||||
import type { tipo_estrutura_visao_grafico } from "../tipagem"
|
||||
|
||||
/** Cria a estrutura de campos para insersão de dados */
|
||||
export const z_tabela: tipo_estrutura_visao_grafico<"z_tabela"> = {
|
||||
visao: "z_tabela",
|
||||
rotulo: "Tabela",
|
||||
tabela: ({ tabela }) => tabela,
|
||||
descricao: ({ tabela, descricao_pelo_usuario, filtros }) => {
|
||||
if (String(descricao_pelo_usuario || "").trim())
|
||||
return String(descricao_pelo_usuario || "").trim()
|
||||
|
||||
return `Consulta na ${tabela} ${
|
||||
!filtros?.length
|
||||
? ""
|
||||
: `, quando ${filtros
|
||||
.map(
|
||||
({ coluna, operador, valor }) => `${coluna} ${operador} ${valor}`,
|
||||
)
|
||||
.join(", ")}`
|
||||
}.`
|
||||
},
|
||||
campos: {
|
||||
tabela: { rotulo: "Tabela", tipo_campo: "tabela", order: 1 },
|
||||
colunas: { rotulo: "Colunas", tipo_campo: "lista_colunas", order: 2 },
|
||||
descricao_pelo_usuario: {
|
||||
rotulo: "Descrição (opcional)",
|
||||
tipo_campo: "texto",
|
||||
order: 3,
|
||||
},
|
||||
coluna_ordem: {
|
||||
rotulo: "Coluna de Ordem",
|
||||
tipo_campo: "coluna",
|
||||
order: 4,
|
||||
},
|
||||
direcao_ordem: {
|
||||
rotulo: "Direção de Ordem",
|
||||
tipo_campo: "ordem",
|
||||
order: 5,
|
||||
},
|
||||
|
||||
filtros: { rotulo: "Filtros", tipo_campo: "lista_filtros", order: 6 },
|
||||
},
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
export * from "./estrutura_de_campos"
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
import { z } from "zod"
|
||||
import { z_filtro } from "../_serie_consultar"
|
||||
|
||||
/** aplica a todas as consultas */
|
||||
export const z_padroes = z.object({
|
||||
tabela: z.string(),
|
||||
filtros: z_filtro.array().optional(),
|
||||
descricao_pelo_usuario: z.string().optional(),
|
||||
})
|
||||
|
||||
export const z_contagem_em_barra_vertical = z
|
||||
.object({
|
||||
colanuEixoX: z.string(),
|
||||
colunaAgrupamento: z.string().array().optional(),
|
||||
})
|
||||
.extend(z_padroes.shape)
|
||||
|
||||
export const z_soma_em_barra_vertical = z
|
||||
.object({
|
||||
colanuEixoX: z.string(),
|
||||
colunaSoma: z.string(),
|
||||
unidadeSoma: z.string().optional(),
|
||||
colunaAgrupamento: z.string().array().optional(),
|
||||
exibirComoPorcentagem: z.boolean().optional(),
|
||||
})
|
||||
.extend(z_padroes.shape)
|
||||
|
||||
export const z_contagem_em_pizza = z
|
||||
.object({
|
||||
classes: z.string(),
|
||||
})
|
||||
.extend(z_padroes.shape)
|
||||
|
||||
export const z_tabela = z
|
||||
.object({
|
||||
colunas: z.string().array(),
|
||||
coluna_ordem: z.string().optional(),
|
||||
direcao_ordem: z.enum(["asc", "desc", "1", "-1"]).optional(),
|
||||
})
|
||||
.extend(z_padroes.shape)
|
||||
|
||||
export const visoes_pilao = {
|
||||
z_contagem_em_barra_vertical,
|
||||
z_contagem_em_pizza,
|
||||
z_tabela,
|
||||
z_soma_em_barra_vertical,
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
import { z } from "zod"
|
||||
import type { visoes_pilao, z_padroes } from "./listaDeVisoes"
|
||||
|
||||
export const z_tipos_campos_reg_grafico = z.enum([
|
||||
"tabela",
|
||||
"coluna",
|
||||
"texto",
|
||||
"lista_colunas",
|
||||
"lista_filtros",
|
||||
"ordem",
|
||||
"booleana",
|
||||
])
|
||||
|
||||
export type tipo_estrutura_visao_grafico<T extends keyof typeof visoes_pilao> =
|
||||
{
|
||||
/** Nome da Visão */
|
||||
visao: T
|
||||
/** Rotulo */
|
||||
rotulo: string
|
||||
/** Retorna a tabela Referente ao Registro */
|
||||
tabela: (
|
||||
_: z.infer<(typeof visoes_pilao)[T]> & z.infer<typeof z_padroes>,
|
||||
) => string
|
||||
/** Descrição */
|
||||
descricao: (
|
||||
_: z.infer<(typeof visoes_pilao)[T]> & z.infer<typeof z_padroes>,
|
||||
) => string
|
||||
/** Lista os campos e suas configurações */
|
||||
campos: {
|
||||
[c in keyof Required<
|
||||
z.infer<(typeof visoes_pilao)[T]> & z.infer<typeof z_padroes>
|
||||
>]: {
|
||||
rotulo: string
|
||||
tipo_campo: z.infer<typeof z_tipos_campos_reg_grafico>
|
||||
order: number
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue