From 6e4720d7cd0a7fcab637dd7355fd5ded56aa864b Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Fri, 20 Jun 2025 16:32:40 +0200 Subject: [PATCH] =?UTF-8?q?debug:=20a=C3=B1ade=20logging=20temporal=20para?= =?UTF-8?q?=20diagn=C3=B3stico=20de=20sincronizaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/group-sync.ts | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/services/group-sync.ts b/src/services/group-sync.ts index 2ab72e3..d3f1eb7 100644 --- a/src/services/group-sync.ts +++ b/src/services/group-sync.ts @@ -74,11 +74,33 @@ export class GroupSyncService { } const groups = await this.fetchGroupsFromAPI(); - const communityGroups = groups.filter( - (group) => group.linkedParent === communityId - ); + console.log('ℹ️ Grupos crudos de la API:', JSON.stringify(groups, null, 2)); + + const communityGroups = groups.filter((group) => { + const matches = group.linkedParent === communityId; + console.log(`ℹ️ Grupo ${group.id} (${group.subject}):`, { + linkedParent: group.linkedParent, + matchesCommunity: matches, + isCommunityItself: group.id === communityId + }); + return matches; + }); + + console.log('ℹ️ Grupos que pasaron el filtro:', communityGroups.map(g => ({ + id: g.id, + name: g.subject, + parent: g.linkedParent + }))); + + const dbGroupsBefore = db.prepare('SELECT id, active FROM groups').all(); + console.log('ℹ️ Grupos en DB antes de upsert:', dbGroupsBefore); - return await this.upsertGroups(communityGroups); + const result = await this.upsertGroups(communityGroups); + + const dbGroupsAfter = db.prepare('SELECT id, active FROM groups').all(); + console.log('ℹ️ Grupos en DB después de upsert:', dbGroupsAfter); + + return result; } catch (error) { console.error('Group sync failed:', error); throw error; @@ -259,8 +281,12 @@ export class GroupSyncService { UPDATE groups SET active = FALSE, last_verified = CURRENT_TIMESTAMP + WHERE active = TRUE `).run(); - console.log('Marked groups inactive:', inactiveResult); + console.log('ℹ️ Grupos marcados como inactivos:', { + count: inactiveResult.changes, + lastId: inactiveResult.lastInsertRowid + }); for (const group of groups) { const existing = db.prepare('SELECT 1 FROM groups WHERE id = ?').get(group.id);