From f049c47f386ea296080f72ed9c5e656ba54e2a83 Mon Sep 17 00:00:00 2001 From: "matthias.lotz" Date: Sun, 9 Nov 2025 23:51:29 +0100 Subject: [PATCH] fix: Add display_in_workshop to groupFormatter and fix filter logic Problem: Moderation filter returned 0 groups because: 1. groupFormatter.formatGroupDetail() didn't include display_in_workshop field 2. Platform filters incorrectly required workshop consent Solution: - Add display_in_workshop and consent_timestamp to formatGroupDetail() - Remove workshop requirement from platform filters - Add default filter to show only groups with workshop consent - Fix workshop-only filter to check for consented social media Filter logic: - 'Alle Gruppen': Only groups WITH workshop consent - 'Nur Werkstatt': Groups with workshop BUT WITHOUT social media - Platform filters: Groups with that platform consent (independent of workshop) --- backend/src/routes/groups.js | 25 +++++++++++++++++-------- backend/src/utils/groupFormatter.js | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/backend/src/routes/groups.js b/backend/src/routes/groups.js index 7c0ffb3..8b924db 100644 --- a/backend/src/routes/groups.js +++ b/backend/src/routes/groups.js @@ -49,23 +49,32 @@ router.get('/moderation/groups', async (req, res) => { }) ); - // Jetzt filtern wir basierend auf den Query-Parametern + // 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) - ); + // Filter: Nur Gruppen MIT Werkstatt-Consent aber OHNE zugestimmte Social Media Consents + filteredGroups = groupsWithConsents.filter(group => { + // Muss Werkstatt-Consent haben + if (!group.display_in_workshop) return false; + + // Darf KEINE zugestimmten Social Media Consents haben + const hasConsentedSocialMedia = group.socialMediaConsents && + group.socialMediaConsents.some(consent => consent.consented === 1 || consent.consented === true); + + return !hasConsentedSocialMedia; + }); } else if (platform) { - // Filter: Gruppen mit bestimmter Social Media Platform + // Filter: Gruppen mit bestimmter Social Media Platform (unabhängig vom Werkstatt-Consent) filteredGroups = groupsWithConsents.filter(group => group.socialMediaConsents && group.socialMediaConsents.some(consent => - consent.platform_name === platform && consent.consented + consent.platform_name === platform && (consent.consented === 1 || consent.consented === true) ) ); + } else { + // Kein Filter: Zeige nur Gruppen MIT Werkstatt-Consent (das ist die Mindestanforderung) + filteredGroups = groupsWithConsents.filter(group => group.display_in_workshop); } res.json({ diff --git a/backend/src/utils/groupFormatter.js b/backend/src/utils/groupFormatter.js index 910f120..1e6dfc6 100644 --- a/backend/src/utils/groupFormatter.js +++ b/backend/src/utils/groupFormatter.js @@ -24,6 +24,8 @@ function formatGroupDetail(groupRow, images) { name: groupRow.name, uploadDate: groupRow.upload_date, approved: Boolean(groupRow.approved), + display_in_workshop: Boolean(groupRow.display_in_workshop), + consent_timestamp: groupRow.consent_timestamp || null, images: images.map(img => ({ id: img.id, fileName: img.file_name,