diff --git a/src/lib/db.js b/src/lib/db.js index 53832d4..e0ee451 100644 --- a/src/lib/db.js +++ b/src/lib/db.js @@ -194,9 +194,16 @@ export async function saveQuizResult(userId, weekNumber, result) { export async function getQuizResult(userId, weekNumber) { try { - const r = await pb.collection('test_results').getFirstListItem( - `user_id="${userId}" && week_number=${weekNumber}`, - ); + // Use getList instead of getFirstListItem so that "no record yet" returns + // an empty items array (HTTP 200) rather than throwing a ClientResponseError + // that the SDK logs to the browser console as a 404. + const res = await pb.collection('test_results').getList(1, 1, { + filter: `user_id="${userId}" && week_number=${weekNumber}`, + skipTotal: true, + requestKey: null, + }); + const r = res.items[0]; + if (!r) return null; // Map snake_case PB fields back to the camelCase shape Testen.jsx expects. return { score: r.score,