From 6cb6c31d8d10074c10b9c38eaa9ae559d05f5a2b Mon Sep 17 00:00:00 2001 From: brobert Date: Mon, 10 Nov 2025 16:57:36 +0100 Subject: [PATCH] fix: usar getDb() en IdentityService y quitar AllowedGroups.dbInstance Co-authored-by: aider (openrouter/openai/gpt-5) --- src/services/group-sync.ts | 16 ++++++++-------- src/services/identity.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/services/group-sync.ts b/src/services/group-sync.ts index 78c7aca..22bd7d0 100644 --- a/src/services/group-sync.ts +++ b/src/services/group-sync.ts @@ -190,7 +190,7 @@ export class GroupSyncService { } // Completar labels faltantes en allowed_groups usando todos los grupos devueltos por la API - try { AllowedGroups.dbInstance = this.dbInstance; this.fillMissingAllowedGroupLabels(groups); } catch {} + try { this.fillMissingAllowedGroupLabels(groups); } catch {} // Actualizar métricas this.cacheActiveGroups(); @@ -270,7 +270,7 @@ export class GroupSyncService { if (!id) continue; const label = nameById.get(id); if (label) { - try { (AllowedGroups as any).dbInstance = this.dbInstance; AllowedGroups.upsertPending(id, label, null); } catch {} + try { AllowedGroups.upsertPending(id, label, null); } catch {} filled++; } } @@ -459,7 +459,7 @@ export class GroupSyncService { const mode = String(process.env.GROUP_GATING_MODE || 'off').toLowerCase(); const enforce = mode === 'enforce'; if (enforce) { - try { AllowedGroups.dbInstance = this.dbInstance; } catch {} + // no-op } let groups = 0, added = 0, updated = 0, deactivated = 0; @@ -502,7 +502,7 @@ export class GroupSyncService { const mode = String(process.env.GROUP_GATING_MODE || 'off').toLowerCase(); const enforce = mode === 'enforce'; if (enforce) { - try { AllowedGroups.dbInstance = this.dbInstance; } catch {} + // no-op } let groups = 0, added = 0, updated = 0, deactivated = 0; @@ -734,7 +734,7 @@ export class GroupSyncService { const cached = this.activeGroupsCache.get(groupId); if (cached && cached.trim()) { try { this.ensureGroupExists(groupId, cached); } catch {} - try { AllowedGroups.dbInstance = this.dbInstance; AllowedGroups.upsertPending(groupId, cached, null); } catch {} + try { AllowedGroups.upsertPending(groupId, cached, null); } catch {} this.cacheActiveGroups(); return cached; } @@ -745,7 +745,7 @@ export class GroupSyncService { const name = row?.name ? String(row.name).trim() : ''; if (name) { try { this.ensureGroupExists(groupId, name); } catch {} - try { AllowedGroups.dbInstance = this.dbInstance; AllowedGroups.upsertPending(groupId, name, null); } catch {} + try { AllowedGroups.upsertPending(groupId, name, null); } catch {} this.cacheActiveGroups(); return name; } @@ -758,7 +758,7 @@ export class GroupSyncService { const subject = g?.subject ? String(g.subject).trim() : ''; if (subject) { try { this.ensureGroupExists(groupId, subject); } catch {} - try { AllowedGroups.dbInstance = this.dbInstance; AllowedGroups.upsertPending(groupId, subject, null); } catch {} + try { AllowedGroups.upsertPending(groupId, subject, null); } catch {} this.cacheActiveGroups(); return subject; } @@ -779,7 +779,7 @@ export class GroupSyncService { const mode = String(process.env.GROUP_GATING_MODE || 'off').toLowerCase(); if (mode === 'enforce') { try { - (AllowedGroups as any).dbInstance = this.dbInstance; + // no-op if (!AllowedGroups.isAllowed(groupId)) { try { Metrics.inc('sync_skipped_group_total'); } catch {} return { added: 0, updated: 0, deactivated: 0 }; diff --git a/src/services/identity.ts b/src/services/identity.ts index 93c2aee..13e1fb3 100644 --- a/src/services/identity.ts +++ b/src/services/identity.ts @@ -16,7 +16,7 @@ export class IdentityService { const u = normalizeWhatsAppId(userId || ''); if (!a || !u || a === u) return false; // Asegurar que el user_id numérico exista para no violar la FK (user_aliases.user_id -> users.id) - try { ensureUserExists(u, this.dbInstance); } catch {} + try { ensureUserExists(u, getDb()); } catch {} try { getDb().prepare(` INSERT INTO user_aliases (alias, user_id, source, created_at, updated_at)