add consultaUsuariosexterno
This commit is contained in:
parent
07a656a2b4
commit
9491278d6c
62 changed files with 489 additions and 200 deletions
29
src/autenticacao/_codigoContaSite.ts
Normal file
29
src/autenticacao/_codigoContaSite.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
type tipoPostCodigoContaSite = { site: string }
|
||||
|
||||
export const codigoContaSite = async ({
|
||||
ambiente,
|
||||
post,
|
||||
buscar,
|
||||
}: {
|
||||
ambiente: "desenvolvimento" | "producao"
|
||||
post: tipoPostCodigoContaSite
|
||||
/** função que conecta com a API */
|
||||
buscar: (
|
||||
url: string,
|
||||
post: tipoPostCodigoContaSite,
|
||||
) => Promise<tipoResposta<string>>
|
||||
}): Promise<tipoResposta<string>> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/codigo_prefeitura_site`
|
||||
|
||||
try {
|
||||
const resp = await buscar(url, post).catch((e) =>
|
||||
respostaComuns.erro(`erro ao buscar código do site: ${e}`),
|
||||
)
|
||||
|
||||
return resp
|
||||
} catch (e) {
|
||||
return respostaComuns.erro(`erro ao buscar código do site: ${e}`)
|
||||
}
|
||||
}
|
||||
25
src/autenticacao/_consultaUsuariosexterno.ts
Normal file
25
src/autenticacao/_consultaUsuariosexterno.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
|
||||
export type tipoUsuarioExterno = {
|
||||
nome: string
|
||||
email: string
|
||||
telefone: string
|
||||
vinculo: string
|
||||
codigo_produto: string
|
||||
chave_produto: string
|
||||
}
|
||||
|
||||
export const consultaUsuariosexterno = async ({
|
||||
token_produto,
|
||||
ambiente,
|
||||
codigo_produto,
|
||||
chave_produto,
|
||||
}: {
|
||||
ambiente: "desenvolvimento" | "producao"
|
||||
token_produto: string
|
||||
codigo_produto: string
|
||||
chave_produto: string
|
||||
}): Promise<tipoResposta<tipoUsuarioExterno[]>> => {
|
||||
console.log(token_produto, ambiente, codigo_produto, chave_produto)
|
||||
return respostaComuns.valor([])
|
||||
}
|
||||
6
src/autenticacao/_urlAutenticacao.ts
Normal file
6
src/autenticacao/_urlAutenticacao.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export const urlAutenticacao = (ambiente: "desenvolvimento" | "producao") =>
|
||||
`${
|
||||
ambiente == "producao"
|
||||
? "https://carro-de-boi.idz.one"
|
||||
: "http://localhost:5030"
|
||||
}/autenticacao`
|
||||
32
src/autenticacao/_validarToken.ts
Normal file
32
src/autenticacao/_validarToken.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import type { tipoResposta } from "p-respostas"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
type tipoPostValidarTokem = { token: string }
|
||||
|
||||
/** faz a validação do token */
|
||||
export const validarToken = async ({
|
||||
ambiente,
|
||||
post,
|
||||
buscar,
|
||||
}: {
|
||||
ambiente: "desenvolvimento" | "producao"
|
||||
post: tipoPostValidarTokem
|
||||
/** função que conecta com a API */
|
||||
buscar: (
|
||||
url: string,
|
||||
post: tipoPostValidarTokem,
|
||||
) => Promise<tipoResposta<any>>
|
||||
}): Promise<"valido" | "erro"> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/validar_token`
|
||||
|
||||
try {
|
||||
const resposta = await buscar(url, post)
|
||||
.then((resposta) =>
|
||||
resposta.eCerto ? ("valido" as const) : ("erro" as const),
|
||||
)
|
||||
.catch(() => "erro" as const)
|
||||
|
||||
return resposta
|
||||
} catch (e) {
|
||||
return "erro"
|
||||
}
|
||||
}
|
||||
14
src/autenticacao/index.ts
Normal file
14
src/autenticacao/index.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { codigoContaSite } from "./_codigoContaSite"
|
||||
import { consultaUsuariosexterno } from "./_consultaUsuariosexterno"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
import { validarToken } from "./_validarToken"
|
||||
|
||||
export type { tipoUsuarioExterno } from "./_consultaUsuariosexterno"
|
||||
|
||||
/** todas as rotas de comunicação com autenticador partem dessa variável */
|
||||
export const pAutenticacao = {
|
||||
validarToken,
|
||||
urlAutenticacao,
|
||||
codigoContaSite,
|
||||
consultaUsuariosexterno,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue