Design store: fix hasScreenshot/rating defaults for pre-existing themes

Themes published before this schema existed have no screenshot/rating
fields at all, so `t.screenshot !== null` (undefined) and the rating
counters (undefined += n) were both wrong for them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Sonnet 5 committed 2026-09-18 06:46:38 +00:00
1 parent eb7cb78042
commit a98cf59111
1 file changed
+7 -5
+7 -5
View File
@@ -439,7 +439,9 @@ function setStoreCors(res: ServerResponse) {
} }
function storeRating(theme: StoreTheme): { average: number; count: number } { function storeRating(theme: StoreTheme): { average: number; count: number } {
return { average: theme.ratingCount ? theme.ratingSum / theme.ratingCount : 0, count: theme.ratingCount }; // theme.ratingCount is undefined for themes submitted before this field existed.
const count = theme.ratingCount ?? 0;
return { average: count ? theme.ratingSum / count : 0, count };
} }
async function handleStoreList(res: ServerResponse) { async function handleStoreList(res: ServerResponse) {
@@ -452,8 +454,8 @@ async function handleStoreList(res: ServerResponse) {
name: t.name, name: t.name,
baseTheme: t.baseTheme, baseTheme: t.baseTheme,
author: t.author, author: t.author,
description: t.description, description: t.description ?? "",
hasScreenshot: t.screenshot !== null, hasScreenshot: Boolean(t.screenshot),
rating: storeRating(t), rating: storeRating(t),
createdAt: t.createdAt, createdAt: t.createdAt,
})); }));
@@ -536,8 +538,8 @@ async function handleStoreRate(req: IncomingMessage, res: ServerResponse, id: st
return; return;
} }
theme.ratingSum += stars; theme.ratingSum = (theme.ratingSum ?? 0) + stars;
theme.ratingCount += 1; theme.ratingCount = (theme.ratingCount ?? 0) + 1;
try { try {
await saveStoreThemes(themes); await saveStoreThemes(themes);
} catch (err) { } catch (err) {