47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import type { tipoResposta } from "p-respostas"
|
|
import { respostaComuns } from "p-respostas"
|
|
import { z } from "zod"
|
|
import { PREFIXO, tiposColunas, type zp_produto_conta } from "./_variaveis"
|
|
|
|
/** Faz o registro de uma nova base de dados configurado a estrutura de colunas */
|
|
|
|
export const zp_registrar_base_dados = z.object({
|
|
tabela: z.string(),
|
|
colunas: z.array(
|
|
z.object({
|
|
coluna: z.string(),
|
|
tipo: tiposColunas,
|
|
}),
|
|
),
|
|
})
|
|
|
|
export const registrar_base_dados = async ({
|
|
emDesenvolvimento,
|
|
cliente: { conta, produto },
|
|
parametros: { colunas, 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_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}`}`,
|
|
)
|
|
|
|
const resp = await fetch(url.toString(), {
|
|
method: "POST",
|
|
body: JSON.stringify({ tabela, colunas }),
|
|
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
|
|
}
|