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)
This commit is contained in:
Matthias Lotz 2025-11-09 23:51:29 +01:00
parent 8d2f09f71a
commit f049c47f38
2 changed files with 19 additions and 8 deletions

View File

@ -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; let filteredGroups = groupsWithConsents;
if (workshopOnly === 'true') { if (workshopOnly === 'true') {
// Filter: Nur Gruppen mit Werkstatt-Consent aber OHNE Social Media Consents // Filter: Nur Gruppen MIT Werkstatt-Consent aber OHNE zugestimmte Social Media Consents
filteredGroups = groupsWithConsents.filter(group => filteredGroups = groupsWithConsents.filter(group => {
group.display_in_workshop && // Muss Werkstatt-Consent haben
(!group.socialMediaConsents || group.socialMediaConsents.length === 0) 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) { } 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 => filteredGroups = groupsWithConsents.filter(group =>
group.socialMediaConsents && group.socialMediaConsents &&
group.socialMediaConsents.some(consent => 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({ res.json({

View File

@ -24,6 +24,8 @@ function formatGroupDetail(groupRow, images) {
name: groupRow.name, name: groupRow.name,
uploadDate: groupRow.upload_date, uploadDate: groupRow.upload_date,
approved: Boolean(groupRow.approved), approved: Boolean(groupRow.approved),
display_in_workshop: Boolean(groupRow.display_in_workshop),
consent_timestamp: groupRow.consent_timestamp || null,
images: images.map(img => ({ images: images.map(img => ({
id: img.id, id: img.id,
fileName: img.file_name, fileName: img.file_name,