sgp - pedro afonso3
This commit is contained in:
1 parent
6bc106a461
commit
c3e262309d
1 file changed
+11
-2
+11
-2
@@ -159,6 +159,11 @@ class SgpAPI {
|
|||||||
return onu.olt_id !== undefined ? String(onu.olt_id) : '';
|
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) {
|
_clienteId(c) {
|
||||||
return c.id ?? c.clienteId ?? c.cliente_id ?? c.idCliente ?? null;
|
return c.id ?? c.clienteId ?? c.cliente_id ?? c.idCliente ?? null;
|
||||||
}
|
}
|
||||||
@@ -200,14 +205,18 @@ class SgpAPI {
|
|||||||
const out = [];
|
const out = [];
|
||||||
|
|
||||||
(c.contratos || []).forEach(ct => {
|
(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);
|
const idStatus = this._statusId(ct.status);
|
||||||
(ct.servicos && ct.servicos.length ? ct.servicos : [{}]).forEach(srv => {
|
(ct.servicos && ct.servicos.length ? ct.servicos : [{}]).forEach(srv => {
|
||||||
const onu = srv.onu || {};
|
const onu = srv.onu || {};
|
||||||
const conexao = onu.conexao || srv.conexao || {};
|
const conexao = onu.conexao || srv.conexao || {};
|
||||||
const e = srv.endereco || end;
|
const e = srv.endereco || end;
|
||||||
out.push({
|
out.push({
|
||||||
id: ct.contrato,
|
id: idContrato,
|
||||||
id_servico: ct.contrato,
|
id_servico: idContrato,
|
||||||
servico_id: srv.id,
|
servico_id: srv.id,
|
||||||
id_cliente: idCliente,
|
id_cliente: idCliente,
|
||||||
idCliente,
|
idCliente,
|
||||||
|
|||||||
Reference in new issue
Block a user