39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
import node_fetch from "cross-fetch";
|
|
import { respostaComuns } from "p-respostas";
|
|
import { z } from "zod";
|
|
import { operadores_pilao, tiposSeriesAgregacoes, urlPilao, } from "./variaveis";
|
|
const filtro = z.object({
|
|
coluna: z.string(),
|
|
valor: z.any(),
|
|
operador: operadores_pilao,
|
|
});
|
|
export const zp_serie_registrar = z.object({
|
|
tabela: z.string(),
|
|
colanuEixoX: z.string(),
|
|
colunaAgrupamento: z.string().array().optional(),
|
|
agregacao: tiposSeriesAgregacoes,
|
|
filtros: filtro.array().optional(),
|
|
});
|
|
export const serie_consultar = (cliente) => (parametros) => {
|
|
const dados = async () => {
|
|
const url = new URL(`${urlPilao(cliente.emDesenvolvimento).api}/${tiposSeriesAgregacoes.enum.contagem}/${cliente.produto}/${cliente.conta}`);
|
|
const resp = await node_fetch(url.toString(), {
|
|
method: "POST",
|
|
body: JSON.stringify(parametros),
|
|
headers: { "Content-Type": "application/json" },
|
|
})
|
|
.then((r) => r.json())
|
|
.catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]))
|
|
.then((r) => r);
|
|
return resp;
|
|
};
|
|
const url = () => {
|
|
const vUrl = new URL(`${urlPilao(cliente.emDesenvolvimento).site}/${tiposSeriesAgregacoes.enum.contagem}/${cliente.produto}/${cliente.conta}`);
|
|
const serie = encodeURIComponent(JSON.stringify(parametros, null, 2));
|
|
return `${vUrl.href}?serie=${serie}`;
|
|
};
|
|
return {
|
|
dados,
|
|
url,
|
|
};
|
|
};
|