This commit is contained in:
Luiz H. R. Silva 2024-06-04 12:18:48 -03:00
parent 2fb80e6683
commit 645b3b551e
6 changed files with 28 additions and 32 deletions

View file

@ -1,4 +1,4 @@
import type { tipoResposta } from "~comuns";
import { type tipoResposta } from "~comuns";
type tipoPostValidarTokem = {
token: string;
};
@ -14,11 +14,11 @@ export declare const pAutenticacao: {
buscar: (url: string, post: tipoPostValidarTokem) => Promise<tipoResposta<any>>;
}) => Promise<"valido" | "erro">;
urlAutenticacao: (ambiente: "desenvolvimento" | "producao") => string;
codigoPrefeituraSite: ({ ambiente, post, buscar, }: {
codigoContaSite: ({ ambiente, post, buscar, }: {
ambiente: "desenvolvimento" | "producao";
post: tipoPostCodigoContaSite;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostCodigoContaSite) => Promise<tipoResposta<string>>;
}) => Promise<"valido" | "erro">;
}) => Promise<tipoResposta<string>>;
};
export {};

View file

@ -1,3 +1,4 @@
import { respostaComuns } from "~comuns";
const urlAutenticacao = (ambiente) => `${ambiente == "producao"
? "https://carro-de-boi.idz.one"
: "http://localhost:5030"}/autenticacao`;
@ -14,21 +15,19 @@ const validarToken = async ({ ambiente, post, buscar, }) => {
return "erro";
}
};
const codigoPrefeituraSite = async ({ ambiente, post, buscar, }) => {
const codigoContaSite = async ({ ambiente, post, buscar, }) => {
const url = `${urlAutenticacao(ambiente)}/autenticacao/api/codigo_prefeitura_site`;
try {
const resposta = await buscar(url, post)
.then((resposta) => resposta.eCerto ? "valido" : "erro")
.catch((e) => "erro");
return resposta;
const resp = await buscar(url, post).catch((e) => respostaComuns.erro(`erro ao buscar código do site: ${e}`));
return resp;
}
catch (e) {
return "erro";
return respostaComuns.erro(`erro ao buscar código do site: ${e}`);
}
};
/** todas as rotas de comunicação com autenticador partem dessa variável */
export const pAutenticacao = {
validarToken,
urlAutenticacao,
codigoPrefeituraSite,
codigoContaSite,
};

View file

@ -1,4 +1,4 @@
import type { tipoResposta } from "~comuns";
import { type tipoResposta } from "~comuns";
type tipoPostValidarTokem = {
token: string;
};
@ -14,11 +14,11 @@ export declare const pAutenticacao: {
buscar: (url: string, post: tipoPostValidarTokem) => Promise<tipoResposta<any>>;
}) => Promise<"valido" | "erro">;
urlAutenticacao: (ambiente: "desenvolvimento" | "producao") => string;
codigoPrefeituraSite: ({ ambiente, post, buscar, }: {
codigoContaSite: ({ ambiente, post, buscar, }: {
ambiente: "desenvolvimento" | "producao";
post: tipoPostCodigoContaSite;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostCodigoContaSite) => Promise<tipoResposta<string>>;
}) => Promise<"valido" | "erro">;
}) => Promise<tipoResposta<string>>;
};
export {};

View file

@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pAutenticacao = void 0;
const _comuns_1 = require("~comuns");
const urlAutenticacao = (ambiente) => `${ambiente == "producao"
? "https://carro-de-boi.idz.one"
: "http://localhost:5030"}/autenticacao`;
@ -17,21 +18,19 @@ const validarToken = async ({ ambiente, post, buscar, }) => {
return "erro";
}
};
const codigoPrefeituraSite = async ({ ambiente, post, buscar, }) => {
const codigoContaSite = async ({ ambiente, post, buscar, }) => {
const url = `${urlAutenticacao(ambiente)}/autenticacao/api/codigo_prefeitura_site`;
try {
const resposta = await buscar(url, post)
.then((resposta) => resposta.eCerto ? "valido" : "erro")
.catch((e) => "erro");
return resposta;
const resp = await buscar(url, post).catch((e) => _comuns_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`));
return resp;
}
catch (e) {
return "erro";
return _comuns_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`);
}
};
/** todas as rotas de comunicação com autenticador partem dessa variável */
exports.pAutenticacao = {
validarToken,
urlAutenticacao,
codigoPrefeituraSite,
codigoContaSite,
};

View file

@ -1,6 +1,6 @@
{
"name": "~drives",
"version": "0.14.0",
"version": "0.15.0",
"description": "",
"main": "src/index.ts",
"exports": {

View file

@ -1,4 +1,4 @@
import type { tipoResposta } from "~comuns"
import { respostaComuns, type tipoResposta } from "~comuns"
type tipoPostValidarTokem = { token: string }
type tipoPostCodigoContaSite = { site: string }
@ -38,7 +38,7 @@ const validarToken = async ({
}
}
const codigoPrefeituraSite = async ({
const codigoContaSite = async ({
ambiente,
post,
buscar,
@ -50,21 +50,19 @@ const codigoPrefeituraSite = async ({
url: string,
post: tipoPostCodigoContaSite,
) => Promise<tipoResposta<string>>
}): Promise<"valido" | "erro"> => {
}): Promise<tipoResposta<string>> => {
const url = `${urlAutenticacao(
ambiente,
)}/autenticacao/api/codigo_prefeitura_site`
try {
const resposta = await buscar(url, post)
.then((resposta) =>
resposta.eCerto ? ("valido" as const) : ("erro" as const),
const resp = await buscar(url, post).catch((e) =>
respostaComuns.erro(`erro ao buscar código do site: ${e}`),
)
.catch((e) => "erro" as const)
return resposta
return resp
} catch (e) {
return "erro"
return respostaComuns.erro(`erro ao buscar código do site: ${e}`)
}
}
@ -72,5 +70,5 @@ const codigoPrefeituraSite = async ({
export const pAutenticacao = {
validarToken,
urlAutenticacao,
codigoPrefeituraSite,
codigoContaSite,
}