Primeiro Commit
This commit is contained in:
commit
fa3fae2202
7
.env
Normal file
7
.env
Normal file
@ -0,0 +1,7 @@
|
||||
HUBSOFT_AUTH_URL='https://api.sothis.hubsoft.com.br/oauth/token'
|
||||
HUBSOFT_CLIENT_ID=35
|
||||
HUBSOFT_CLIENT_SECRET=1s62YsDijmzLz17NaKbnK1AUCKAx10RSDPMOtVcN
|
||||
HUBSOFT_USERNAME=contato@vexvigilancia.com.br
|
||||
HUBSOFT_PASSWORD="19T(6Jnp*"
|
||||
HUBSOFT_GRANT_TYPE=password
|
||||
HUBSOFT_CONSULTAR_ATENDIMENTO_URL="https://api.sothis.hubsoft.com.br/api/v1/integracao/atendimento/todos?pagina=0&itens_por_pagina=500&"
|
||||
15
config/apiConfig.js
Normal file
15
config/apiConfig.js
Normal file
@ -0,0 +1,15 @@
|
||||
require('dotenv').config();
|
||||
|
||||
module.exports = {
|
||||
hubsoft: {
|
||||
authUrl: process.env.HUBSOFT_AUTH_URL,
|
||||
authPayload: {
|
||||
client_id: process.env.HUBSOFT_CLIENT_ID,
|
||||
client_secret: process.env.HUBSOFT_CLIENT_SECRET,
|
||||
username: process.env.HUBSOFT_USERNAME,
|
||||
password: process.env.HUBSOFT_PASSWORD,
|
||||
grant_type: process.env.HUBSOFT_GRANT_TYPE
|
||||
},
|
||||
consultarAtendimentoUrl: process.env.HUBSOFT_CONSULTAR_ATENDIMENTO_URL
|
||||
}
|
||||
};
|
||||
39
controller/hubsoftController.js
Normal file
39
controller/hubsoftController.js
Normal file
@ -0,0 +1,39 @@
|
||||
const hubsoftService = require('../services/hubsoftServices.js');
|
||||
|
||||
|
||||
const processaAtendimentos = async () => {
|
||||
try {
|
||||
const atendimentos = await hubsoftService.consultarAtendimento();
|
||||
|
||||
console.log('Resposta atendimentos:', {
|
||||
type: typeof atendimentos,
|
||||
isArray: Array.isArray(atendimentos),
|
||||
length: Array.isArray(atendimentos) ? atendimentos.length : undefined
|
||||
});
|
||||
|
||||
if (!Array.isArray(atendimentos) || atendimentos.length === 0) {
|
||||
console.warn('Nenhum atendimento disponível para o filtro.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Converter para number antes da comparação para evitar falhas por string/número
|
||||
const consultarAtendimentos = atendimentos.find(atendimento => {
|
||||
const status = Number(atendimento.id_atendimento_status);
|
||||
const tipo = Number(atendimento.id_atendimento_tipo);
|
||||
return status === 33 && tipo === 4;
|
||||
});
|
||||
|
||||
if (!consultarAtendimentos) {
|
||||
const candidatos = atendimentos.filter(a =>
|
||||
Number(a.id_atendimento_status) === 33 || Number(a.id_atendimento_tipo) === 4
|
||||
);
|
||||
console.log('Nenhum atendimento com status 33 e tipo 4. Exemplos próximos:', candidatos.slice(0, 5));
|
||||
} else {
|
||||
console.log('Atendimento encontrado:', consultarAtendimentos);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erro no controller ao consultar atendimentos:', error);
|
||||
}
|
||||
};
|
||||
|
||||
processaAtendimentos();
|
||||
11
package.json
Normal file
11
package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "integra-hubsoft-glpi",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "GabrielPereira",
|
||||
"license": "ISC",
|
||||
"description": ""
|
||||
}
|
||||
37
services/hubsoftServices.js
Normal file
37
services/hubsoftServices.js
Normal file
@ -0,0 +1,37 @@
|
||||
const apiConfig = require('../config/apiConfig.js');
|
||||
const axios = require('axios');
|
||||
|
||||
async function getAuthToken() {
|
||||
try {
|
||||
const response = await axios.post(apiConfig.hubsoft.authUrl, apiConfig.hubsoft.authPayload);
|
||||
return response.data.access_token;
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error fetching auth token:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const consultarAtendimento = async () => {
|
||||
try {
|
||||
const token = await getAuthToken();
|
||||
const today = new Date();
|
||||
const date = new Date(today.getFullYear(), today.getMonth(), today.getDate()).toISOString().split('T')[0];
|
||||
console.log('Consulting atendimentos for date:', date);
|
||||
const url = `${apiConfig.hubsoft.consultarAtendimentoUrl}data_inicio=2025-10-03&data_fim=2025-10-06`;
|
||||
|
||||
const response = await axios.get(url, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
|
||||
return response.data.atendimentos;
|
||||
|
||||
}catch (error) {
|
||||
console.error('Error consulting atendimentos:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
consultarAtendimento, getAuthToken
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user