47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import node_fetch from "cross-fetch"
|
|
import { respostaComuns, type tipoResposta } from "p-respostas"
|
|
import type { z } from "zod"
|
|
import type { tipos_de_acesso_quipo } from "../tokenQuipo"
|
|
import type { zAmbiente } from "../ts/ambiente"
|
|
import { urlAutenticacao } from "./_urlAutenticacao"
|
|
|
|
export type tipoUsuarioExterno = {
|
|
_nome: string
|
|
_email: string
|
|
_telefone: string
|
|
vinculo: string
|
|
codigo_conta: string
|
|
chave_produto: string
|
|
codigo: string
|
|
_cpf: string
|
|
}
|
|
|
|
export const usuarios_quipo = async ({
|
|
token_produto,
|
|
ambiente,
|
|
tipo,
|
|
}: {
|
|
ambiente: z.infer<typeof zAmbiente>
|
|
token_produto: string
|
|
tipo: tipos_de_acesso_quipo
|
|
}): Promise<tipoResposta<tipoUsuarioExterno[]>> => {
|
|
const url = `${urlAutenticacao(ambiente)}/api/usuarios_quipo`
|
|
|
|
if (!token_produto) return respostaComuns.erro("token_produto não informado")
|
|
|
|
const headers = {
|
|
token: token_produto,
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
return node_fetch(url, {
|
|
method: "POST",
|
|
body: JSON.stringify({ tipo }),
|
|
headers,
|
|
})
|
|
.then((r) => r.json())
|
|
.catch((e) =>
|
|
respostaComuns.erro(`Erro ao buscar usuários quipo governo ${e.message}`),
|
|
)
|
|
.then((r) => r as tipoResposta<tipoUsuarioExterno[]>)
|
|
}
|