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.
This commit is contained in:
parent
a34d7eab7a
commit
8d2f09f71a
|
|
@ -35,22 +35,12 @@ router.get('/moderation/groups', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { workshopOnly, platform } = req.query;
|
const { workshopOnly, platform } = req.query;
|
||||||
|
|
||||||
let groups;
|
// Hole alle Gruppen mit vollständigen Infos (inkl. Bilder)
|
||||||
|
let allGroups = await GroupRepository.getAllGroupsWithModerationInfo();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Füge Consent-Daten für jede Gruppe hinzu
|
// Füge Consent-Daten für jede Gruppe hinzu
|
||||||
const groupsWithConsents = await Promise.all(
|
const groupsWithConsents = await Promise.all(
|
||||||
groups.map(async (group) => {
|
allGroups.map(async (group) => {
|
||||||
const consents = await GroupRepository.getSocialMediaConsentsForGroup(group.groupId);
|
const consents = await GroupRepository.getSocialMediaConsentsForGroup(group.groupId);
|
||||||
return {
|
return {
|
||||||
...group,
|
...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({
|
res.json({
|
||||||
groups: groupsWithConsents,
|
groups: filteredGroups,
|
||||||
totalCount: groupsWithConsents.length,
|
totalCount: filteredGroups.length,
|
||||||
pendingCount: groupsWithConsents.filter(g => !g.approved).length,
|
pendingCount: filteredGroups.filter(g => !g.approved).length,
|
||||||
approvedCount: groupsWithConsents.filter(g => g.approved).length
|
approvedCount: filteredGroups.filter(g => g.approved).length
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching moderation groups:', error);
|
console.error('Error fetching moderation groups:', error);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user