@ -87,30 +87,30 @@ export class GroupSyncService {
console.log('ℹ️ Grupos crudos de la API:',JSON.stringify(groups,null,2));
console.log('ℹ️ Sin filtrar por comunidad (modo multicomunidad). Total grupos:',groups.length);
constdbGroupsBefore=this.dbInstance.prepare('SELECT id, active, COALESCE(archived,0) AS archived, name FROM groups').all();
constdbGroupsBefore=this.dbInstance.prepare('SELECT id, active, COALESCE(archived,0) AS archived, COALESCE(is_community,0) AS is_community, name FROM groups').all();
console.log('ℹ️ Grupos en DB antes de upsert:',dbGroupsBefore);
constresult=awaitthis.upsertGroups(groups);
constdbGroupsAfter=this.dbInstance.prepare('SELECT id, active, COALESCE(archived,0) AS archived, name FROM groups').all();
constdbGroupsAfter=this.dbInstance.prepare('SELECT id, active, COALESCE(archived,0) AS archived, COALESCE(is_community,0) AS is_community, name FROM groups').all();
console.log('ℹ️ Grupos en DB después de upsert:',dbGroupsAfter);
// Detectar grupos que pasaron de activos a inactivos (y no están archivados) en este sync
@ -274,7 +274,7 @@ export class GroupSyncService {
}
privatestaticcacheActiveGroups():void{
constgroups=this.dbInstance.prepare('SELECT id, name FROM groups WHERE active = TRUE').all();
constgroups=this.dbInstance.prepare('SELECT id, name FROM groups WHERE active = TRUE AND COALESCE(is_community,0) = 0 AND COALESCE(archived,0) = 0').all();
this.activeGroupsCache.clear();
for(constgroupofgroups){
this.activeGroupsCache.set(group.id,group.name);
@ -288,6 +288,9 @@ export class GroupSyncService {
@ -324,7 +327,7 @@ export class GroupSyncService {
}
privatestaticgetActiveGroupsCount():number{
constresult=this.dbInstance.prepare('SELECT COUNT(*) as count FROM groups WHERE active = TRUE').get();
constresult=this.dbInstance.prepare('SELECT COUNT(*) as count FROM groups WHERE active = TRUE AND COALESCE(is_community,0) = 0 AND COALESCE(archived,0) = 0').get();
returnresult?.count||0;
}
@ -412,21 +415,49 @@ export class GroupSyncService {
constexisting=this.dbInstance.prepare('SELECT 1 FROM groups WHERE id = ?').get(group.id);
'UPDATE groups SET name = ?, community_id = COALESCE(?, community_id), is_community = ?, active = TRUE, last_verified = CURRENT_TIMESTAMP WHERE id = ?'