This commit is contained in:
Luiz Silva 2025-01-07 10:57:57 -03:00
parent e5bbcf11d3
commit 8d240bbee9
6 changed files with 25 additions and 26 deletions

View file

@ -53,24 +53,22 @@ export class ClassPilao {
this.#ver_log = ver_log
}
#gerarUrl(acao: string, extraPath?: string): { rota: string; url: string } {
const rota = `${PREFIXO_PILAO}/api/${acao}/${this.#produto}/${this.#conta}${
extraPath ? `/${extraPath}` : ""
}`
const url = `${this.baseUrlApi}${rota}`
#gerarUrlApi(acao: string): { rota: string; url: URL } {
const rota = `${PREFIXO_PILAO}/api/${acao}/${this.#produto}/${this.#conta}`
const url = new URL(`${this.baseUrlApi}${rota}`)
return { rota, url }
}
rotaEnviarRegistros() {
return this.#gerarUrl(pilao_enderecos["enviar-registros"])
return this.#gerarUrlApi(pilao_enderecos["enviar-registros"])
}
rotaDeletarRegistro() {
return this.#gerarUrl(pilao_enderecos["deletar-registros"])
return this.#gerarUrlApi(pilao_enderecos["deletar-registros"])
}
rotaConsultarSerie(tipoVisao: nomesVisoes | ":tipoVisao") {
return this.#gerarUrl(pilao_enderecos["consultar-serie"], tipoVisao)
rotaConsultarSerie() {
return this.#gerarUrlApi(pilao_enderecos["consultar-serie"])
}
rotaIframeSerie(tipoVisao: nomesVisoes | ":tipoVisao") {
@ -80,7 +78,7 @@ export class ClassPilao {
}
rotaFuncaoApi(funcao: keyof tipo_pilao_api | ":funcao") {
return this.#gerarUrl("API", funcao)
return this.#gerarUrlApi(funcao)
}
async consultarApi<T extends keyof tipo_pilao_api>(
@ -200,7 +198,7 @@ export class ClassPilao {
`[PILÃO]: Enviando ${registros.length} registros na tabela "${tabela}" para "${url}".`,
)
const resp = await this.processarRegistros(
url,
url.href,
registros,
tabela,
"enviar",
@ -216,7 +214,7 @@ export class ClassPilao {
const codigos = [...(this.#codigosParaDeletar[tabela] || [])]
const url = this.rotaDeletarRegistro().url
const resp = await this.processarRegistros(
url,
url.href,
codigos,
tabela,
"deletar",
@ -249,7 +247,8 @@ export class ClassPilao {
const dados = async (): Promise<
tipoResposta<tipoRetornoSerieconsulta<T>>
> => {
const url = this.rotaConsultarSerie(tipoVisao).url
const url = this.rotaConsultarSerie().url
url.searchParams.set("visao", tipoVisao)
const resp = await crossFetch(url.toString(), {
method: "POST",
body: JSON.stringify(parametros),