implementado drive pilão de dados
This commit is contained in:
parent
a1e543cfb8
commit
daae40f4b2
54 changed files with 1476 additions and 19 deletions
47
src/pilao-de-dados/registrar_base_dados.ts
Normal file
47
src/pilao-de-dados/registrar_base_dados.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue