2025-10-06 13:36:15 -03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-06 13:53:04 -03:00
|
|
|
// Função para consultar atendimentos
|
|
|
|
|
|
2025-10-06 13:36:15 -03:00
|
|
|
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
|
|
|
|
|
};
|