43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import node_fetch from "cross-fetch"
|
|
import { respostaComuns, type tipoResposta } from "p-respostas"
|
|
import type { z } from "zod"
|
|
import type { zAmbiente } from "../ts/ambiente"
|
|
import { urlAutenticacao } from "./_urlAutenticacao"
|
|
|
|
export const usuarios_quipo_vincular = async ({
|
|
token_produto,
|
|
ambiente,
|
|
conta,
|
|
vinculo,
|
|
codigo_usuario,
|
|
email,
|
|
}: {
|
|
ambiente: z.infer<typeof zAmbiente>
|
|
token_produto: string
|
|
conta: string
|
|
vinculo: string
|
|
codigo_usuario?: string
|
|
email: string
|
|
}): Promise<tipoResposta<string>> => {
|
|
const url = `${urlAutenticacao(ambiente)}/api/vinculos__criar`
|
|
|
|
if (!token_produto) return respostaComuns.erro("token_produto não informado")
|
|
const headers = {
|
|
token: token_produto,
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
const parametros = {
|
|
vinculos: { codigo_conta: conta, codigo_usuario, vinculo },
|
|
email: email,
|
|
}
|
|
return await node_fetch(url, {
|
|
headers,
|
|
body: JSON.stringify(parametros),
|
|
method: "POST",
|
|
})
|
|
.then(async (r) => await r.json())
|
|
.catch((e) =>
|
|
respostaComuns.erro(`Erro ao criar vinculo de usuario ${e.message}`),
|
|
)
|
|
}
|