refatoração

This commit is contained in:
Luiz H. R. Silva 2024-06-16 15:42:20 -03:00
parent 117bdbef7b
commit 8b8406e245
28 changed files with 300 additions and 51 deletions

View file

@ -21,3 +21,4 @@ export declare const validarColuna: {
lista_texto: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
lista_numero: z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>;
};
export declare const baseUrlPilao: (emDesenvolvimento?: boolean | null | undefined) => "https://carro-de-boi.idz.one" | "http://127.0.0.1:5080";

View file

@ -29,3 +29,4 @@ export const validarColuna = {
lista_texto: z.array(z.string()).nullable(),
lista_numero: z.array(z.number()).nullable(),
};
export const baseUrlPilao = (emDesenvolvimento) => emDesenvolvimento ? "http://127.0.0.1:5080" : "https://carro-de-boi.idz.one";

View file

@ -0,0 +1,20 @@
import type { tipoResposta } from "p-respostas";
import { z } from "zod";
import { type zp_produto_conta } from "./_variaveis";
export declare const zp_deletar_registros: z.ZodObject<{
tabela: z.ZodString;
codigos: z.ZodArray<z.ZodString, "many">;
}, "strip", z.ZodTypeAny, {
tabela: string;
codigos: string[];
}, {
tabela: string;
codigos: string[];
}>;
export declare const deletar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, 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_deletar_registros>;
}) => Promise<tipoResposta<true>>;

View file

@ -0,0 +1,36 @@
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, baseUrlPilao } from "./_variaveis";
//enviar registros para base de dados
export const zp_deletar_registros = z.object({
tabela: z.string(),
codigos: z.array(z.string()),
});
export const deletar_registros = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }) => __awaiter(void 0, void 0, void 0, function* () {
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${PREFIXO}/${Object.keys({ deletar_registros })[0]}/${produto}/${conta}`);
const tamanhoBlocos = 1000;
while (codigos.length > 0) {
const bloco = codigos.splice(0, tamanhoBlocos);
const resp = yield fetch(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela, codigos: bloco }),
headers: { "Content-Type": "application/json" },
})
.then((r) => r.json())
.catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]))
.then((r) => r);
if (resp.eErro) {
return resp;
}
}
return respostaComuns.valor(true);
});

View file

@ -9,16 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
import { respostaComuns } from "p-respostas";
import { z } from "zod";
import { PREFIXO } from "./_variaveis";
import { PREFIXO, baseUrlPilao } from "./_variaveis";
//enviar registros para base de dados
export const zp_enviar_registros = z.object({
tabela: z.string(),
registros: z.array(z.any()),
});
export const enviar_registros = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, 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}/enviar-registro/${produto}/${conta}`);
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${PREFIXO}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`);
const tamanhoBlocos = 1000;
while (registros.length > 0) {
const bloco = registros.splice(0, tamanhoBlocos);

View file

@ -135,4 +135,25 @@ export declare const pPilao: {
conta: string;
}>;
validarZ: <T>(zodType: import("zod").ZodType<T, any, T>, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<T>;
deletar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }: {
emDesenvolvimento?: boolean | null | undefined;
cliente: {
produto: string;
conta: string;
};
parametros: {
tabela: string;
codigos: string[];
};
}) => Promise<import("p-respostas").tipoResposta<true>>;
zp_deletar_registros: import("zod").ZodObject<{
tabela: import("zod").ZodString;
codigos: import("zod").ZodArray<import("zod").ZodString, "many">;
}, "strip", import("zod").ZodTypeAny, {
tabela: string;
codigos: string[];
}, {
tabela: string;
codigos: string[];
}>;
};

View file

@ -1,4 +1,5 @@
import { tiposSeriesAgregacoes, validarZ, zp_produto_conta } from "./_variaveis";
import { deletar_registros, zp_deletar_registros } from "./deletar_registros";
import { enviar_registros, zp_enviar_registros } from "./enviar_registros";
import { registrar_base_dados, zp_registrar_base_dados, } from "./registrar_base_dados";
import { serie_consultar, zp_serie_consultar } from "./serie_consultar";
@ -15,4 +16,6 @@ export const pPilao = {
zp_serie_consultar,
zp_produto_conta,
validarZ,
deletar_registros,
zp_deletar_registros,
};

View file

@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
import { respostaComuns } from "p-respostas";
import { z } from "zod";
import { PREFIXO, tiposColunasBasedados, } from "./_variaveis";
import { PREFIXO, baseUrlPilao, 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(),
@ -19,9 +19,7 @@ export const zp_registrar_base_dados = z.object({
})),
});
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 url = new URL(`${baseUrlPilao(emDesenvolvimento)}${`${PREFIXO}/${Object.keys({ registrar_base_dados })[0]}/${produto}/${conta}`}`);
const resp = yield fetch(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela, colunas }),

View file

@ -9,16 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
import { respostaComuns } from "p-respostas";
import { z } from "zod";
import { PREFIXO, tiposSeriesAgregacoes, } from "./_variaveis";
import { PREFIXO, baseUrlPilao, tiposSeriesAgregacoes, } from "./_variaveis";
//consultar compilação
export const zp_serie_consultar = z.object({
identificador: z.string(),
});
export const serie_consultar = ({ emDesenvolvimento, parametros: { identificador }, cliente: { conta, produto }, }) => {
const dados = () => __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}/${tiposSeriesAgregacoes.enum.contagem}/${produto}/${conta}`}`);
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${`${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}/${produto}/${conta}`}`);
const resp = yield fetch(url.toString(), {
method: "POST",
body: JSON.stringify({

View file

@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
import { respostaComuns } from "p-respostas";
import { z } from "zod";
import { PREFIXO, tiposSeriesAgregacoes, } from "./_variaveis";
import { PREFIXO, baseUrlPilao, tiposSeriesAgregacoes, } from "./_variaveis";
//registrar serie
export const zp_serie_registrar = z.object({
tabela: z.string(),
@ -19,9 +19,7 @@ export const zp_serie_registrar = z.object({
agregacao: tiposSeriesAgregacoes,
});
export const serie_registrar = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { agregacao, colanuEixoX, colunaAgrupamento, identificador, 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-serie/${produto}/${conta}`}`);
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${`${PREFIXO}/${Object.keys({ serie_registrar })[0]}/${produto}/${conta}`}`);
const resp = yield fetch(url.toString(), {
method: "POST",
body: JSON.stringify({