diff --git a/src/sgp/api.js b/src/sgp/api.js index 4a32efe..8119097 100644 --- a/src/sgp/api.js +++ b/src/sgp/api.js @@ -159,6 +159,11 @@ class SgpAPI { return onu.olt_id !== undefined ? String(onu.olt_id) : ''; } + _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; + } + _clienteId(c) { return c.id ?? c.clienteId ?? c.cliente_id ?? c.idCliente ?? null; } @@ -200,14 +205,18 @@ class SgpAPI { const out = []; (c.contratos || []).forEach(ct => { + const idContrato = this._contratoId(ct); + 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 || {}; const conexao = onu.conexao || srv.conexao || {}; const e = srv.endereco || end; out.push({ - id: ct.contrato, - id_servico: ct.contrato, + id: idContrato, + id_servico: idContrato, servico_id: srv.id, id_cliente: idCliente, idCliente,