diff --git a/dist-import/pilao-de-dados/_variaveis.d.ts b/dist-import/pilao-de-dados/_variaveis.d.ts index b818a8e..7035257 100644 --- a/dist-import/pilao-de-dados/_variaveis.d.ts +++ b/dist-import/pilao-de-dados/_variaveis.d.ts @@ -21,3 +21,4 @@ export declare const validarColuna: { lista_texto: z.ZodNullable>; lista_numero: z.ZodNullable>; }; +export declare const baseUrlPilao: (emDesenvolvimento?: boolean | null | undefined) => "https://carro-de-boi.idz.one" | "http://127.0.0.1:5080"; diff --git a/dist-import/pilao-de-dados/_variaveis.js b/dist-import/pilao-de-dados/_variaveis.js index def75ed..6723f15 100644 --- a/dist-import/pilao-de-dados/_variaveis.js +++ b/dist-import/pilao-de-dados/_variaveis.js @@ -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"; diff --git a/dist-import/pilao-de-dados/deletar_registros.d.ts b/dist-import/pilao-de-dados/deletar_registros.d.ts new file mode 100644 index 0000000..5b036e0 --- /dev/null +++ b/dist-import/pilao-de-dados/deletar_registros.d.ts @@ -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; +}, "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; + /** Parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-import/pilao-de-dados/deletar_registros.js b/dist-import/pilao-de-dados/deletar_registros.js new file mode 100644 index 0000000..4ac471b --- /dev/null +++ b/dist-import/pilao-de-dados/deletar_registros.js @@ -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); +}); diff --git a/dist-import/pilao-de-dados/enviar_registros.js b/dist-import/pilao-de-dados/enviar_registros.js index 163c952..5f879aa 100644 --- a/dist-import/pilao-de-dados/enviar_registros.js +++ b/dist-import/pilao-de-dados/enviar_registros.js @@ -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); diff --git a/dist-import/pilao-de-dados/index.d.ts b/dist-import/pilao-de-dados/index.d.ts index 3db2344..1ed5eaf 100644 --- a/dist-import/pilao-de-dados/index.d.ts +++ b/dist-import/pilao-de-dados/index.d.ts @@ -135,4 +135,25 @@ export declare const pPilao: { conta: string; }>; validarZ: (zodType: import("zod").ZodType, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso; + deletar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + codigos: string[]; + }; + }) => Promise>; + zp_deletar_registros: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + codigos: import("zod").ZodArray; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + codigos: string[]; + }, { + tabela: string; + codigos: string[]; + }>; }; diff --git a/dist-import/pilao-de-dados/index.js b/dist-import/pilao-de-dados/index.js index 554aaf0..e1cbc3b 100644 --- a/dist-import/pilao-de-dados/index.js +++ b/dist-import/pilao-de-dados/index.js @@ -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, }; diff --git a/dist-import/pilao-de-dados/registrar_base_dados.js b/dist-import/pilao-de-dados/registrar_base_dados.js index e566813..190b870 100644 --- a/dist-import/pilao-de-dados/registrar_base_dados.js +++ b/dist-import/pilao-de-dados/registrar_base_dados.js @@ -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 }), diff --git a/dist-import/pilao-de-dados/serie_consultar.js b/dist-import/pilao-de-dados/serie_consultar.js index 2ad955a..4cfb4f2 100644 --- a/dist-import/pilao-de-dados/serie_consultar.js +++ b/dist-import/pilao-de-dados/serie_consultar.js @@ -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({ diff --git a/dist-import/pilao-de-dados/serie_registrar.js b/dist-import/pilao-de-dados/serie_registrar.js index 89103a6..a2df969 100644 --- a/dist-import/pilao-de-dados/serie_registrar.js +++ b/dist-import/pilao-de-dados/serie_registrar.js @@ -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({ diff --git a/dist-require/pilao-de-dados/_variaveis.d.ts b/dist-require/pilao-de-dados/_variaveis.d.ts index b818a8e..7035257 100644 --- a/dist-require/pilao-de-dados/_variaveis.d.ts +++ b/dist-require/pilao-de-dados/_variaveis.d.ts @@ -21,3 +21,4 @@ export declare const validarColuna: { lista_texto: z.ZodNullable>; lista_numero: z.ZodNullable>; }; +export declare const baseUrlPilao: (emDesenvolvimento?: boolean | null | undefined) => "https://carro-de-boi.idz.one" | "http://127.0.0.1:5080"; diff --git a/dist-require/pilao-de-dados/_variaveis.js b/dist-require/pilao-de-dados/_variaveis.js index 0eda90a..77f7b49 100644 --- a/dist-require/pilao-de-dados/_variaveis.js +++ b/dist-require/pilao-de-dados/_variaveis.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.validarColuna = exports.tiposSeriesAgregacoes = exports.tiposColunasBasedados = exports.zp_produto_conta = exports.validarZ = exports.PREFIXO = exports.zAmbiente = void 0; +exports.baseUrlPilao = exports.validarColuna = exports.tiposSeriesAgregacoes = exports.tiposColunasBasedados = exports.zp_produto_conta = exports.validarZ = exports.PREFIXO = exports.zAmbiente = void 0; var p_respostas_1 = require("p-respostas"); var zod_1 = require("zod"); exports.zAmbiente = zod_1.z.enum(["desenvolvimento", "producao"]); @@ -33,3 +33,7 @@ exports.validarColuna = { lista_texto: zod_1.z.array(zod_1.z.string()).nullable(), lista_numero: zod_1.z.array(zod_1.z.number()).nullable(), }; +var baseUrlPilao = function (emDesenvolvimento) { + return emDesenvolvimento ? "http://127.0.0.1:5080" : "https://carro-de-boi.idz.one"; +}; +exports.baseUrlPilao = baseUrlPilao; diff --git a/dist-require/pilao-de-dados/deletar_registros.d.ts b/dist-require/pilao-de-dados/deletar_registros.d.ts new file mode 100644 index 0000000..5b036e0 --- /dev/null +++ b/dist-require/pilao-de-dados/deletar_registros.d.ts @@ -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; +}, "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; + /** Parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-require/pilao-de-dados/deletar_registros.js b/dist-require/pilao-de-dados/deletar_registros.js new file mode 100644 index 0000000..bc1a5b0 --- /dev/null +++ b/dist-require/pilao-de-dados/deletar_registros.js @@ -0,0 +1,82 @@ +"use strict"; +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()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deletar_registros = exports.zp_deletar_registros = void 0; +var p_respostas_1 = require("p-respostas"); +var zod_1 = require("zod"); +var _variaveis_1 = require("./_variaveis"); +//enviar registros para base de dados +exports.zp_deletar_registros = zod_1.z.object({ + tabela: zod_1.z.string(), + codigos: zod_1.z.array(zod_1.z.string()), +}); +var deletar_registros = function (_a) { + var emDesenvolvimento = _a.emDesenvolvimento, _b = _a.cliente, conta = _b.conta, produto = _b.produto, _c = _a.parametros, codigos = _c.codigos, tabela = _c.tabela; + return __awaiter(void 0, void 0, void 0, function () { + var url, tamanhoBlocos, bloco, resp; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat(_variaveis_1.PREFIXO, "/").concat(Object.keys({ deletar_registros: exports.deletar_registros })[0], "/").concat(produto, "/").concat(conta)); + tamanhoBlocos = 1000; + _d.label = 1; + case 1: + if (!(codigos.length > 0)) return [3 /*break*/, 3]; + bloco = codigos.splice(0, tamanhoBlocos); + return [4 /*yield*/, fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ tabela: tabela, codigos: bloco }), + headers: { "Content-Type": "application/json" }, + }) + .then(function (r) { return r.json(); }) + .catch(function (e) { + return p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]); + }) + .then(function (r) { return r; })]; + case 2: + resp = _d.sent(); + if (resp.eErro) { + return [2 /*return*/, resp]; + } + return [3 /*break*/, 1]; + case 3: return [2 /*return*/, p_respostas_1.respostaComuns.valor(true)]; + } + }); + }); +}; +exports.deletar_registros = deletar_registros; diff --git a/dist-require/pilao-de-dados/enviar_registros.js b/dist-require/pilao-de-dados/enviar_registros.js index 2a1cfee..751e65f 100644 --- a/dist-require/pilao-de-dados/enviar_registros.js +++ b/dist-require/pilao-de-dados/enviar_registros.js @@ -52,9 +52,7 @@ var enviar_registros = function (_a) { return __generator(this, function (_d) { switch (_d.label) { case 0: - url = new URL("".concat(emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one").concat(_variaveis_1.PREFIXO, "/enviar-registro/").concat(produto, "/").concat(conta)); + url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat(_variaveis_1.PREFIXO, "/").concat(Object.keys({ enviar_registros: exports.enviar_registros })[0], "/").concat(produto, "/").concat(conta)); tamanhoBlocos = 1000; _d.label = 1; case 1: diff --git a/dist-require/pilao-de-dados/index.d.ts b/dist-require/pilao-de-dados/index.d.ts index 3db2344..1ed5eaf 100644 --- a/dist-require/pilao-de-dados/index.d.ts +++ b/dist-require/pilao-de-dados/index.d.ts @@ -135,4 +135,25 @@ export declare const pPilao: { conta: string; }>; validarZ: (zodType: import("zod").ZodType, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso; + deletar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + codigos: string[]; + }; + }) => Promise>; + zp_deletar_registros: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + codigos: import("zod").ZodArray; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + codigos: string[]; + }, { + tabela: string; + codigos: string[]; + }>; }; diff --git a/dist-require/pilao-de-dados/index.js b/dist-require/pilao-de-dados/index.js index 575132c..81e5a3a 100644 --- a/dist-require/pilao-de-dados/index.js +++ b/dist-require/pilao-de-dados/index.js @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.pPilao = exports.tiposSeriesAgregacoes = void 0; var _variaveis_1 = require("./_variaveis"); Object.defineProperty(exports, "tiposSeriesAgregacoes", { enumerable: true, get: function () { return _variaveis_1.tiposSeriesAgregacoes; } }); +var deletar_registros_1 = require("./deletar_registros"); var enviar_registros_1 = require("./enviar_registros"); var registrar_base_dados_1 = require("./registrar_base_dados"); var serie_consultar_1 = require("./serie_consultar"); @@ -18,4 +19,6 @@ exports.pPilao = { zp_serie_consultar: serie_consultar_1.zp_serie_consultar, zp_produto_conta: _variaveis_1.zp_produto_conta, validarZ: _variaveis_1.validarZ, + deletar_registros: deletar_registros_1.deletar_registros, + zp_deletar_registros: deletar_registros_1.zp_deletar_registros, }; diff --git a/dist-require/pilao-de-dados/registrar_base_dados.js b/dist-require/pilao-de-dados/registrar_base_dados.js index bc495c7..9aee958 100644 --- a/dist-require/pilao-de-dados/registrar_base_dados.js +++ b/dist-require/pilao-de-dados/registrar_base_dados.js @@ -55,9 +55,7 @@ var registrar_base_dados = function (_a) { return __generator(this, function (_d) { switch (_d.label) { case 0: - url = new URL("".concat(emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one").concat("".concat(_variaveis_1.PREFIXO, "/registar-base-dados/").concat(produto, "/").concat(conta))); + url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat("".concat(_variaveis_1.PREFIXO, "/").concat(Object.keys({ registrar_base_dados: exports.registrar_base_dados })[0], "/").concat(produto, "/").concat(conta))); return [4 /*yield*/, fetch(url.toString(), { method: "POST", body: JSON.stringify({ tabela: tabela, colunas: colunas }), diff --git a/dist-require/pilao-de-dados/serie_consultar.js b/dist-require/pilao-de-dados/serie_consultar.js index 397f988..0dfe5d9 100644 --- a/dist-require/pilao-de-dados/serie_consultar.js +++ b/dist-require/pilao-de-dados/serie_consultar.js @@ -51,9 +51,7 @@ var serie_consultar = function (_a) { return __generator(this, function (_a) { switch (_a.label) { case 0: - url = new URL("".concat(emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one").concat("".concat(_variaveis_1.PREFIXO, "/").concat(_variaveis_1.tiposSeriesAgregacoes.enum.contagem, "/").concat(produto, "/").concat(conta))); + url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat("".concat(_variaveis_1.PREFIXO, "/").concat(_variaveis_1.tiposSeriesAgregacoes.enum.contagem, "/").concat(produto, "/").concat(conta))); return [4 /*yield*/, fetch(url.toString(), { method: "POST", body: JSON.stringify({ diff --git a/dist-require/pilao-de-dados/serie_registrar.js b/dist-require/pilao-de-dados/serie_registrar.js index e74bc35..662c38e 100644 --- a/dist-require/pilao-de-dados/serie_registrar.js +++ b/dist-require/pilao-de-dados/serie_registrar.js @@ -55,9 +55,7 @@ var serie_registrar = function (_a) { return __generator(this, function (_d) { switch (_d.label) { case 0: - url = new URL("".concat(emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one").concat("".concat(_variaveis_1.PREFIXO, "/registar-serie/").concat(produto, "/").concat(conta))); + url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat("".concat(_variaveis_1.PREFIXO, "/").concat(Object.keys({ serie_registrar: exports.serie_registrar })[0], "/").concat(produto, "/").concat(conta))); return [4 /*yield*/, fetch(url.toString(), { method: "POST", body: JSON.stringify({ diff --git a/package.json b/package.json index 00521b0..042a971 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p-drives", - "version": "0.63.0", + "version": "0.65.0", "description": "", "main": "src/index.ts", "exports": { diff --git a/src/pilao-de-dados/_variaveis.ts b/src/pilao-de-dados/_variaveis.ts index 021316c..6589d1b 100644 --- a/src/pilao-de-dados/_variaveis.ts +++ b/src/pilao-de-dados/_variaveis.ts @@ -43,3 +43,6 @@ export const validarColuna = { lista_texto: z.array(z.string()).nullable(), lista_numero: z.array(z.number()).nullable(), } + +export const baseUrlPilao = (emDesenvolvimento?: boolean | null | undefined) => + emDesenvolvimento ? "http://127.0.0.1:5080" : "https://carro-de-boi.idz.one" diff --git a/src/pilao-de-dados/deletar_registros.ts b/src/pilao-de-dados/deletar_registros.ts new file mode 100644 index 0000000..23d03ad --- /dev/null +++ b/src/pilao-de-dados/deletar_registros.ts @@ -0,0 +1,52 @@ +import type { tipoResposta } from "p-respostas" +import { respostaComuns } from "p-respostas" +import { z } from "zod" +import { PREFIXO, baseUrlPilao, type zp_produto_conta } 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 = async ({ + emDesenvolvimento, + cliente: { conta, produto }, + parametros: { codigos, tabela }, +}: { + emDesenvolvimento?: boolean | undefined | null + + /** Identificação do cliente */ + cliente: z.infer + /** Parametros da função */ + + parametros: z.infer +}): Promise> => { + 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 = await 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 as tipoResposta) + + if (resp.eErro) { + return resp + } + } + + return respostaComuns.valor(true) +} diff --git a/src/pilao-de-dados/enviar_registros.ts b/src/pilao-de-dados/enviar_registros.ts index 896fa64..1c56d75 100644 --- a/src/pilao-de-dados/enviar_registros.ts +++ b/src/pilao-de-dados/enviar_registros.ts @@ -1,7 +1,7 @@ import type { tipoResposta } from "p-respostas" import { respostaComuns } from "p-respostas" import { z } from "zod" -import { PREFIXO, type zp_produto_conta } from "./_variaveis" +import { PREFIXO, baseUrlPilao, type zp_produto_conta } from "./_variaveis" //enviar registros para base de dados export const zp_enviar_registros = z.object({ @@ -23,11 +23,9 @@ export const enviar_registros = async ({ parametros: z.infer }): Promise> => { const url = new URL( - `${ - emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one" - }${PREFIXO}/enviar-registro/${produto}/${conta}`, + `${baseUrlPilao( + emDesenvolvimento, + )}${PREFIXO}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`, ) const tamanhoBlocos = 1000 diff --git a/src/pilao-de-dados/index.ts b/src/pilao-de-dados/index.ts index 231dc22..11c0e60 100644 --- a/src/pilao-de-dados/index.ts +++ b/src/pilao-de-dados/index.ts @@ -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, @@ -24,4 +25,7 @@ export const pPilao = { zp_produto_conta, validarZ, + + deletar_registros, + zp_deletar_registros, } diff --git a/src/pilao-de-dados/registrar_base_dados.ts b/src/pilao-de-dados/registrar_base_dados.ts index ae6d5ae..55fe228 100644 --- a/src/pilao-de-dados/registrar_base_dados.ts +++ b/src/pilao-de-dados/registrar_base_dados.ts @@ -3,6 +3,7 @@ import { respostaComuns } from "p-respostas" import { z } from "zod" import { PREFIXO, + baseUrlPilao, tiposColunasBasedados, type zp_produto_conta, } from "./_variaveis" @@ -31,11 +32,9 @@ export const registrar_base_dados = async ({ parametros: z.infer }): Promise> => { const url = new URL( - `${ - emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one" - }${`${PREFIXO}/registar-base-dados/${produto}/${conta}`}`, + `${baseUrlPilao( + emDesenvolvimento, + )}${`${PREFIXO}/${Object.keys({ registrar_base_dados })[0]}/${produto}/${conta}`}`, ) const resp = await fetch(url.toString(), { diff --git a/src/pilao-de-dados/serie_consultar.ts b/src/pilao-de-dados/serie_consultar.ts index 106e5e3..b1b315a 100644 --- a/src/pilao-de-dados/serie_consultar.ts +++ b/src/pilao-de-dados/serie_consultar.ts @@ -3,6 +3,7 @@ import { respostaComuns } from "p-respostas" import { z } from "zod" import { PREFIXO, + baseUrlPilao, tiposSeriesAgregacoes, type zp_produto_conta, } from "./_variaveis" @@ -33,11 +34,7 @@ export const serie_consultar = ({ }> > => { const url = new URL( - `${ - emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one" - }${`${PREFIXO}/${ + `${baseUrlPilao(emDesenvolvimento)}${`${PREFIXO}/${ tiposSeriesAgregacoes.enum.contagem }/${produto}/${conta}`}`, ) diff --git a/src/pilao-de-dados/serie_registrar.ts b/src/pilao-de-dados/serie_registrar.ts index a9424c4..1fe75d6 100644 --- a/src/pilao-de-dados/serie_registrar.ts +++ b/src/pilao-de-dados/serie_registrar.ts @@ -3,6 +3,7 @@ import { z } from "zod" import { PREFIXO, + baseUrlPilao, tiposSeriesAgregacoes, type zp_produto_conta, } from "./_variaveis" @@ -36,11 +37,9 @@ export const serie_registrar = async ({ parametros: z.infer }): Promise> => { const url = new URL( - `${ - emDesenvolvimento - ? "http://127.0.0.1:5080" - : "https://carro-de-boi.idz.one" - }${`${PREFIXO}/registar-serie/${produto}/${conta}`}`, + `${baseUrlPilao( + emDesenvolvimento, + )}${`${PREFIXO}/${Object.keys({ serie_registrar })[0]}/${produto}/${conta}`}`, ) const resp = await fetch(url.toString(), {