From c3e262309d81a5bc3506b8571532ec8f0c06c0b4 Mon Sep 17 00:00:00 2001 From: Rodrigo Bertoldo de Sousa Martins Date: Wed, 14 Oct 2026 15:49:29 -0300 Subject: [PATCH] sgp - pedro afonso3 --- src/sgp/api.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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,