From 3f6c81a8460145562931a0bc3248b84e62a40bae Mon Sep 17 00:00:00 2001 From: Paul Nothaft Date: Tue, 1 Sep 2026 16:30:46 +0200 Subject: [PATCH] fix(photos): treat category_id 0 as uncategorized instead of storing it Genuine product bug, found behind the adminPhotos.reference suite (which was failing for an unrelated reason -- see below). parseInt('0') is 0 and !isNaN(0) is true, so a '0' category_id was written literally. photo_categories.id is an increments() column, so 0 can never be a real category, and every read path already assumes it cannot happen: the list mapper does `category_id || type` (0 is falsy, renders as uncategorized) and the list filter explicitly skips '0'. The result was a filter black hole -- the photo matches no numeric category filter, and misses the "uncategorized" filter too because that is whereNull(). Displayed as uncategorized, reachable by nothing. null rather than a 400: unparseable input ('abc' -> NaN) already falls through to null, so 400ing on '0' while silently accepting 'abc' would be incoherent, and '0' is just the HTML whose "none" + // option carries value="0" is exactly how '0' reaches this route. Storing 0 + // left the photo in a black hole — the grid's category filters never match + // it, and the "uncategorized" filter is whereNull() so it misses it too, + // while the list mapper renders it as uncategorized because 0 is falsy. + // NaN (unparseable input) already fell through to null and still does. const numericCategoryId = parseInt(category_id, 10); - if (!isNaN(numericCategoryId)) { + if (numericCategoryId > 0) { updateData.category_id = numericCategoryId; } else { updateData.category_id = null; @@ -1031,8 +1041,9 @@ router.post('/:eventId/photos/bulk-update', adminAuth, requirePermission('photos updateData.category_id = null; } else { // Handle numeric category IDs from photo_categories table + // (0/negative mean "no category" — see the PATCH route above) const numericCategoryId = parseInt(updates.category_id, 10); - if (!isNaN(numericCategoryId)) { + if (numericCategoryId > 0) { updateData.category_id = numericCategoryId; } else { updateData.category_id = null;