fixed skip clue implimentation

This commit is contained in:
bobbert committed 2025-03-18 22:25:07 +00:00
1 parent fccc2a4edc
commit 2f9a6c732c
18 files changed
+524 -151

No files matched your search

+18 -4
View File
@@ -42,12 +42,25 @@ export async function GET(request) {
const totalClues = clueCountResult?.total || 0;
// Get all found clues with timestamps, ordered by found time
// Only include clues that aren't marked as skipped
const foundClues = await query(
`
SELECT c.id, c.title, tc.found_at
FROM clues c
JOIN team_clues tc ON c.id = tc.clue_id
WHERE tc.team_id = ?
WHERE tc.team_id = ? AND (tc.skipped = 0 OR tc.skipped IS NULL)
ORDER BY tc.found_at ASC
`,
[token.teamId]
);
// Get skipped clues separately
const skippedClues = await query(
`
SELECT c.id, c.title, tc.found_at
FROM clues c
JOIN team_clues tc ON c.id = tc.clue_id
WHERE tc.team_id = ? AND tc.skipped = 1
ORDER BY tc.found_at ASC
`,
[token.teamId]
@@ -69,12 +82,12 @@ export async function GET(request) {
);
// If there are unfound clues, the ones after the first unfound are "skipped"
let skippedClues = 0;
let skippedCluesCount = 0;
if (unfoundClueIds.length > 0) {
const lowestUnfoundId = Math.min(...unfoundClueIds);
// Skipped clues are found clues with IDs higher than the lowest unfound
skippedClues = foundClues.filter((c) => c.id > lowestUnfoundId).length;
skippedCluesCount = foundClues.filter((c) => c.id > lowestUnfoundId).length;
}
// Get current team rank
@@ -107,12 +120,13 @@ export async function GET(request) {
totalClues,
foundClues,
remainingClues: totalClues - foundClues.length,
skippedClues,
skippedCluesCount,
currentRank,
progress:
totalClues > 0 ? Math.round((foundClues.length / totalClues) * 100) : 0,
};
// Return only the teamStats object instead of trying to include undefined variables
return Response.json(teamStats);
} catch (error) {
console.error("Error fetching team stats:", error);