34 lines
1.7 KiB
JavaScript
34 lines
1.7 KiB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
import { respostaComuns } from "p-respostas";
|
|
import { z } from "zod";
|
|
import { PREFIXO, tiposColunasBasedados, } 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: tiposColunasBasedados,
|
|
})),
|
|
});
|
|
export const registrar_base_dados = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { colunas, tabela }, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
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 = yield 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);
|
|
return resp;
|
|
});
|