339 lines
8.1 KiB
JavaScript
339 lines
8.1 KiB
JavaScript
|
|
// Função de comunicação com a rota mounting, para a construção do ambiente do usuário
|
|
async function Autenticao() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
const response = await fetch(`${apiUrl}/mounting`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token ? token : ''
|
|
}
|
|
});
|
|
|
|
let ResponseAutenticao = response.status;
|
|
|
|
|
|
return { response, apiUrl, ResponseAutenticao }; // Retorne um objeto com a resposta e apiUrl
|
|
}
|
|
|
|
|
|
async function IntegracaoZamade() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
const Chamados = await fetch(`${apiUrl}/tickets`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token,
|
|
//'Id_Cliente': domain
|
|
}
|
|
});
|
|
|
|
let ResutadosChamados = Chamados.status;
|
|
//console.log(ResutadosChamados);
|
|
|
|
|
|
return { Chamados, ResutadosChamados }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
|
|
|
|
|
|
async function IntegracaoBoleto_Conect() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
// Requisição POST com as opções corretas
|
|
const Response_Conect = await fetch(`${apiUrl}/boletos`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token
|
|
}
|
|
});
|
|
|
|
const Boleto_Conect = await fetch(`${apiUrl}/boletos`, {
|
|
method: 'OPTIONS',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token
|
|
}
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!Boleto_Conect.ok) {
|
|
throw new Error(`Erro na API de geração de boletos: ${Boleto_Conect.status} - ${Boleto_Conect.statusText}`);
|
|
}
|
|
|
|
return { Boleto_Conect, Response_Conect, apiUrl }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
|
|
|
|
async function IntegracaoBoleto_Alinhamento() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
|
|
// Requisição POST com as opções corretas
|
|
await fetch(`${apiUrl}/<codigo_solicitacao>`, {
|
|
method: 'GET',
|
|
headers: { 'x-access-token': token }
|
|
});
|
|
|
|
|
|
const Boleto_Aline = await fetch(`${apiUrl}/<codigo_solicitacao>`, {
|
|
method: 'OPTIONS',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token
|
|
}
|
|
});
|
|
|
|
|
|
if (!Boleto_Aline.ok) {
|
|
throw new Error(`Erro na API de geração de boletos: ${Boleto_Aline.status} - ${Boleto_Aline.statusText}`);
|
|
}
|
|
|
|
return { Boleto_Aline, apiUrl }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
|
|
|
|
async function IntegracaoBoleto_GerarPDF() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
// Requisição POST com as opções corretas
|
|
await fetch(`${apiUrl}/<codigo_solicitacao>/pdf`, {
|
|
method: 'GET',
|
|
headers: { 'x-access-token': token }
|
|
});
|
|
|
|
const Boleto_PDF = await fetch(`${apiUrl}/<codigo_solicitacao>/pdf`, {
|
|
method: 'OPTIONS',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token
|
|
}
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!Boleto_PDF.ok) {
|
|
throw new Error(`Erro na API de geração de boletos: ${Boleto_PDF.status} - ${Boleto_PDF.statusText}`);
|
|
}
|
|
|
|
return { Boleto_PDF, apiUrl }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
|
|
async function IntegracaoPDF() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
await fetch(`${apiUrl}/baixar_boleto/<codigo_solicitacao>`, { method: 'GET' });
|
|
|
|
const PDF = await fetch(`${apiUrl}/baixar_boleto/<codigo_solicitacao>`, {
|
|
method: 'OPTIONS',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token
|
|
}
|
|
});
|
|
|
|
|
|
if (!PDF.ok) {
|
|
throw new Error(`Erro na API de Geração de Pdfs: ${PDF.status} - ${PDF.statusText}`);
|
|
}
|
|
|
|
return { PDF, apiUrl }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
|
|
async function IntegracaoZabix() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
|
|
const Zabix = await fetch(`${apiUrl}/metrics`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token,
|
|
//'Id_Cliente': domain
|
|
}
|
|
});
|
|
|
|
let ResutadosZabix = Zabix.status;
|
|
//console.log(ResutadosZabix);
|
|
|
|
|
|
return { Zabix, ResutadosZabix }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
/*
|
|
async function IntegracaoUser() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
const empresa = await fetch(`${apiUrl}/zabbixhosts`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token,
|
|
//'Id_Cliente': domain
|
|
}
|
|
});
|
|
|
|
|
|
if (!empresa.ok) {
|
|
throw new Error(`Erro na API do Zabix: ${empresa.status} - ${empresa.statusText}`);
|
|
}
|
|
|
|
return { empresa, apiUrl }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
*/
|
|
async function EmpresasServicos() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
const Servicos = await fetch(`${apiUrl}/servicos`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token,
|
|
//'Id_Cliente': domain
|
|
}
|
|
});
|
|
|
|
let ResutadosES = Servicos.status;
|
|
//console.log(ResutadosES);
|
|
|
|
|
|
return { Servicos, ResutadosES }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
|
|
async function ConsultasEmpresas() {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
const Empresinhas = await fetch(`${apiUrl}/empresas`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token,
|
|
//'Id_Cliente': domain
|
|
}
|
|
});
|
|
|
|
|
|
if (!Empresinhas.ok) {
|
|
throw new Error(`Erro na API das empresas: ${Empresinhas.status} - ${Empresinhas.statusText}`);
|
|
}
|
|
|
|
return { Empresinhas, apiUrl }; // Retorna a resposta e a URL
|
|
|
|
}
|
|
|
|
// Envios de formularios
|
|
|
|
|
|
async function NovoUser(novoUser) {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
const User = await fetch(`${apiUrl}/inserir`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token,
|
|
},
|
|
body: JSON.stringify(novoUser)
|
|
});
|
|
|
|
|
|
if (!User.ok) {
|
|
throw new Error(`Erro na criação de Usuário: ${User.status} - ${User.statusText}`);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
async function NovasImagens(dataperfil) {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
for (let [key, value] of dataperfil.entries()) {
|
|
//console.log(`${key}:`, value);
|
|
}
|
|
|
|
|
|
if (!apiUrl || !token) {
|
|
throw new Error("Erro: Parâmetros obrigatórios ausentes (apiUrl, token ou domain)");
|
|
}
|
|
|
|
const ImagemUser = await fetch(`${apiUrl}/imagem`, {
|
|
method: 'POST',
|
|
headers: {
|
|
//'Content-Type': 'application/json',
|
|
'x-access-token': token,
|
|
},
|
|
body: dataperfil // Dados enviados para a API
|
|
});
|
|
|
|
|
|
|
|
if (!ImagemUser.ok) {
|
|
throw new Error(`Erro na atualização de Imagens: ${ImagemUser.status} - ${ImagemUser.statusText}`);
|
|
}
|
|
|
|
|
|
}
|