From 526dcd8dfc030d86143cee799a88a1004d96b116 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 16 Sep 2025 09:57:35 +0200 Subject: [PATCH] fix(gallery/filters): always apply global liked/favorited filters by aggregate counts (ignore guest_id); resolves mismatch between client guest_id and server identifier --- backend/src/routes/gallery.js | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/backend/src/routes/gallery.js b/backend/src/routes/gallery.js index 92e7bba..caa6e7f 100644 --- a/backend/src/routes/gallery.js +++ b/backend/src/routes/gallery.js @@ -107,33 +107,8 @@ router.get('/:slug/photos', verifyGalleryAccess, async (req, res) => { .select('photos.*') .orderBy('photos.uploaded_at', 'desc'); - // Apply filtering if requested - if (filter && guest_id) { - let filters = {}; - - // Parse filter parameter - if (filter === 'liked') { - filters.liked = true; - } else if (filter === 'favorited') { - filters.favorited = true; - } else if (filter === 'liked,favorited' || filter === 'favorited,liked') { - filters.liked = true; - filters.favorited = true; - filters.operator = 'OR'; - } - - // Get filtered photo IDs - const filteredPhotoIds = await feedbackService.getFilteredPhotos( - req.event.id, - guest_id, - filters - ); - - // Filter photos to only include those with feedback - photos = photos.filter(photo => filteredPhotoIds.includes(photo.id)); - } else if (filter && !guest_id) { - // Global filtering (by aggregate counts) when no guest identifier is provided - // Normalize filter string + // Apply filtering if requested (global, based on aggregate counts) + if (filter) { const f = String(filter).toLowerCase(); if (f === 'liked') { photos = photos.filter(p => (p.like_count || 0) > 0);