TopSapp: fix API show blocked services from client
Signed-off-by: Rodrigo Bertoldo de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
670dfed4bc
commit
b794418d81
4 files changed
+1026
-1721
No files matched your search
+862
-1717
File diff suppressed because it is too large.
Load diff
+73
-4
@@ -508,10 +508,18 @@ class TopSappAPI {
|
||||
|
||||
if (response.success && response.data) {
|
||||
console.log(`✅ Sucesso na tentativa ${i + 1} - Total de itens: ${response.data.dados?.length || response.data.length || 0}`);
|
||||
logger.debug(`Sucesso na tentativa ${i + 1}`, {
|
||||
totalItems: response.data.dados?.length || response.data.length || 0,
|
||||
hasData: !!response.data
|
||||
});
|
||||
|
||||
// Normalizar os dados de status dos serviços
|
||||
if (response.data.dados && Array.isArray(response.data.dados)) {
|
||||
response.data.dados = response.data.dados.map(servico => ({
|
||||
...servico,
|
||||
// Garantir que id_status está consistente
|
||||
id_status: this.interpretarStatusServico(servico),
|
||||
status: this.obterTextoStatus(this.interpretarStatusServico(servico))
|
||||
}));
|
||||
|
||||
console.log(`🔄 Status dos serviços normalizados`);
|
||||
}
|
||||
|
||||
// Verificar se os dados são relevantes para o cliente
|
||||
const dados = response.data.dados || response.data;
|
||||
@@ -551,6 +559,67 @@ class TopSappAPI {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpretar status do serviço corretamente
|
||||
*/
|
||||
interpretarStatusServico(servico) {
|
||||
// Verificar diferentes campos de status
|
||||
|
||||
// Se tem id_status explícito, usar ele
|
||||
if (servico.id_status) {
|
||||
return parseInt(servico.id_status, 10);
|
||||
}
|
||||
|
||||
// Interpretar pelo campo status textual
|
||||
if (servico.status) {
|
||||
const statusLower = servico.status.toLowerCase();
|
||||
|
||||
if (statusLower.includes('liberado') || statusLower.includes('ativo')) {
|
||||
return 1; // Ativo/Liberado
|
||||
}
|
||||
|
||||
if (statusLower.includes('bloqueado')) {
|
||||
return 2; // Bloqueado
|
||||
}
|
||||
|
||||
if (statusLower.includes('desativado') || statusLower.includes('inativo')) {
|
||||
return 3; // Desativado
|
||||
}
|
||||
}
|
||||
|
||||
// Verificar por datas
|
||||
if (servico.data_desativacao && servico.data_desativacao !== '0000-00-00' && servico.data_desativacao !== null) {
|
||||
return 3; // Desativado
|
||||
}
|
||||
|
||||
if (servico.data_bloqueio && servico.data_bloqueio !== '0000-00-00' && servico.data_bloqueio !== null) {
|
||||
// Verificar se foi desbloqueado depois
|
||||
if (!servico.data_desbloqueio || servico.data_desbloqueio === '0000-00-00' || servico.data_desbloqueio === null) {
|
||||
return 2; // Bloqueado
|
||||
}
|
||||
|
||||
// Se tem data de desbloqueio, verificar qual é mais recente
|
||||
if (new Date(servico.data_desbloqueio) < new Date(servico.data_bloqueio)) {
|
||||
return 2; // Bloqueado (bloqueio é mais recente)
|
||||
}
|
||||
}
|
||||
|
||||
// Por padrão, considerar ativo
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obter texto descritivo do status
|
||||
*/
|
||||
obterTextoStatus(idStatus) {
|
||||
switch (parseInt(idStatus, 10)) {
|
||||
case 1: return 'liberado';
|
||||
case 2: return 'bloqueado';
|
||||
case 3: return 'desativado';
|
||||
default: return 'desconhecido';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obter faturas em aberto do cliente
|
||||
*/
|
||||
|
||||
@@ -1165,6 +1165,49 @@ class TopSappManager {
|
||||
return 'Período não informado';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias para obterServicosCliente
|
||||
*/
|
||||
async obterServicos(idCliente, location = '') {
|
||||
return await this.obterServicosCliente(idCliente, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias para bloquearServicoEspecifico
|
||||
*/
|
||||
async bloquearServico(idServico, idCliente, location = '') {
|
||||
return await this.bloquearServicoEspecifico(idCliente, idServico, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias para liberarServicoEspecifico
|
||||
*/
|
||||
async liberarServico(idServico, idCliente, location = '') {
|
||||
return await this.liberarServicoEspecifico(idCliente, idServico, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obter faturas do cliente
|
||||
*/
|
||||
async obterFaturas(idCliente, location = '') {
|
||||
if (!this.isReady()) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'TopSapp não está configurado'
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const credentials = this.config.getCredentialsByLocation(location);
|
||||
return await this.api.obterFaturas(idCliente, location, credentials);
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TopSappManager;
|
||||
Reference in new issue
Block a user