39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
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(); |