fix4
This commit is contained in:
1 parent
c3e262309d
commit
01164f909b
1 file changed
+17
-1
+17
-1
@@ -159,6 +159,16 @@ class SgpAPI {
|
||||
return onu.olt_id !== undefined ? String(onu.olt_id) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug: imprime no log a estrutura bruta do cliente retornada pelo SGP
|
||||
* (senhas/tokens mascarados) para facilitar o mapeamento de campos.
|
||||
*/
|
||||
_logEstrutura(cliente) {
|
||||
if (!cliente || process.env.SGP_DEBUG === 'false') return;
|
||||
const mascarar = (k, v) => (/senha|password|token|secret/i.test(k) ? '***' : v);
|
||||
console.log('🧪 [SGP] Estrutura bruta do cliente:\n' + JSON.stringify(cliente, mascarar, 2));
|
||||
}
|
||||
|
||||
_contratoId(ct) {
|
||||
const v = ct.contrato ?? ct.id ?? ct.contrato_id ?? ct.contratoId ?? ct.clientecontrato_id ?? ct.cliente_contrato_id;
|
||||
return v !== null && typeof v === 'object' ? (v.id ?? v.contrato) : v;
|
||||
@@ -205,13 +215,18 @@ class SgpAPI {
|
||||
const out = [];
|
||||
|
||||
(c.contratos || []).forEach(ct => {
|
||||
const idContrato = this._contratoId(ct);
|
||||
const primeiroSrv = (ct.servicos && ct.servicos[0]) || {};
|
||||
const idContrato = this._contratoId(ct) ?? this._contratoId(primeiroSrv);
|
||||
if (idContrato === undefined) {
|
||||
console.warn('⚠️ [SGP] Contrato sem id reconhecido. Campos recebidos:', Object.keys(ct));
|
||||
}
|
||||
const idStatus = this._statusId(ct.status);
|
||||
(ct.servicos && ct.servicos.length ? ct.servicos : [{}]).forEach(srv => {
|
||||
const onu = srv.onu || {};
|
||||
if (!(onu.serial || onu.phy_addr || onu.addr || onu.serial_onu || srv.serial)) {
|
||||
console.warn('⚠️ [SGP] Serial da ONU não veio no cadastro. Campos do contrato:', Object.keys(ct),
|
||||
'| do serviço:', Object.keys(srv), '| da onu:', Object.keys(onu));
|
||||
}
|
||||
const conexao = onu.conexao || srv.conexao || {};
|
||||
const e = srv.endereco || end;
|
||||
out.push({
|
||||
@@ -332,6 +347,7 @@ class SgpAPI {
|
||||
const id = parseInt(idCliente, 10);
|
||||
if (isNaN(id)) throw new Error(`ID do cliente inválido: ${idCliente}`);
|
||||
const clientes = await this._listarClientes(credentials, { cliente_id: id });
|
||||
this._logEstrutura(clientes[0]);
|
||||
const dados = [];
|
||||
clientes.forEach(c => dados.push(...this._mapServicos({ ...c, id: this._clienteId(c) ?? id })));
|
||||
await this._completarDadosOnu(credentials, dados);
|
||||
|
||||
Reference in new issue
Block a user