From 8d2f09f71a8489a0c99b848bcbd65956c58fd361 Mon Sep 17 00:00:00 2001 From: "matthias.lotz" Date: Sun, 9 Nov 2025 22:28:59 +0100 Subject: [PATCH] fix: Fix moderation filter - load all groups with images first, then filter Problem: Filtered groups were missing preview images because getGroupsByConsentStatus() only returned group metadata without images. Solution: Load all groups with getAllGroupsWithModerationInfo() first (includes images), add consent data, then filter in-memory based on query parameters. This ensures preview images are always included. --- backend/src/routes/groups.js | 43 ++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/backend/src/routes/groups.js b/backend/src/routes/groups.js index 0c2e2af..7c0ffb3 100644 --- a/backend/src/routes/groups.js +++ b/backend/src/routes/groups.js @@ -35,22 +35,12 @@ router.get('/moderation/groups', async (req, res) => { try { const { workshopOnly, platform } = req.query; - let groups; - - if (workshopOnly === 'true') { - // Filter: Nur Gruppen mit Werkstatt-Consent aber ohne Social Media - groups = await GroupRepository.getGroupsByConsentStatus(true, null); - } else if (platform) { - // Filter: Gruppen mit bestimmter Social Media Platform - groups = await GroupRepository.getGroupsByConsentStatus(true, platform); - } else { - // Alle Gruppen mit Consent-Daten - groups = await GroupRepository.getAllGroupsWithModerationInfo(); - } + // Hole alle Gruppen mit vollständigen Infos (inkl. Bilder) + let allGroups = await GroupRepository.getAllGroupsWithModerationInfo(); // Füge Consent-Daten für jede Gruppe hinzu const groupsWithConsents = await Promise.all( - groups.map(async (group) => { + allGroups.map(async (group) => { const consents = await GroupRepository.getSocialMediaConsentsForGroup(group.groupId); return { ...group, @@ -59,11 +49,30 @@ router.get('/moderation/groups', async (req, res) => { }) ); + // Jetzt filtern wir basierend auf den Query-Parametern + let filteredGroups = groupsWithConsents; + + if (workshopOnly === 'true') { + // Filter: Nur Gruppen mit Werkstatt-Consent aber OHNE Social Media Consents + filteredGroups = groupsWithConsents.filter(group => + group.display_in_workshop && + (!group.socialMediaConsents || group.socialMediaConsents.length === 0) + ); + } else if (platform) { + // Filter: Gruppen mit bestimmter Social Media Platform + filteredGroups = groupsWithConsents.filter(group => + group.socialMediaConsents && + group.socialMediaConsents.some(consent => + consent.platform_name === platform && consent.consented + ) + ); + } + res.json({ - groups: groupsWithConsents, - totalCount: groupsWithConsents.length, - pendingCount: groupsWithConsents.filter(g => !g.approved).length, - approvedCount: groupsWithConsents.filter(g => g.approved).length + groups: filteredGroups, + totalCount: filteredGroups.length, + pendingCount: filteredGroups.filter(g => !g.approved).length, + approvedCount: filteredGroups.filter(g => g.approved).length }); } catch (error) { console.error('Error fetching moderation groups:', error);