fixed elapsed timer on clue page cannot fix it on admin page. I am done. now to move on to the styling to match UI

This commit is contained in:
bobbert committed 2025-03-18 23:09:57 +00:00
1 parent 4cd449c0cf
commit 8fd2cabbe0
10 files changed
+226 -136

No files matched your search

+2 -13
View File
@@ -1,7 +1,7 @@
import { query, queryOne, run } from "@/lib/db";
import { getToken } from "next-auth/jwt";
export const dynamic = "force-dynamic"; // Disable caching
export const dynamic = "force-dynamic";
export async function GET(request) {
try {
@@ -17,7 +17,6 @@ export async function GET(request) {
return Response.json({ error: "Unauthorized" }, { status: 401 });
}
// Check if user has a team
if (!token.teamId) {
console.log("API: User without team tried to access clues");
return Response.json(
@@ -26,9 +25,7 @@ export async function GET(request) {
);
}
// First, ensure the team_clues table has the 'skipped' column
try {
// Check if team_clues table exists, create it if it doesn't
await run(`
CREATE TABLE IF NOT EXISTS team_clues (
team_id INTEGER NOT NULL,
@@ -40,7 +37,6 @@ export async function GET(request) {
)
`);
// Check if skipped column exists
const tableInfo = await query("PRAGMA table_info(team_clues)");
const hasSkippedColumn = tableInfo.some((col) => col.name === "skipped");
@@ -52,18 +48,14 @@ export async function GET(request) {
}
} catch (schemaError) {
console.error("Error ensuring database schema:", schemaError);
// Continue execution - if this fails, the main query might still work
// with existing columns
}
// Get all clues with explicit ordering
const clues = await query(`
SELECT id, title, description, location
FROM clues
ORDER BY id ASC
`);
// For each clue, check if the team has found it
const cluesWithStatus = await Promise.all(
clues.map(async (clue) => {
let clueStatus;
@@ -74,7 +66,6 @@ export async function GET(request) {
);
} catch (error) {
console.error(`Error querying status for clue ${clue.id}:`, error);
// Fallback if query fails (e.g., skipped column still doesn't exist)
clueStatus = await queryOne(
"SELECT found_at FROM team_clues WHERE team_id = ? AND clue_id = ?",
[token.teamId, clue.id]
@@ -85,19 +76,17 @@ export async function GET(request) {
...clue,
found: !!clueStatus && !(clueStatus.skipped === 1),
skipped: !!clueStatus && clueStatus.skipped === 1,
available: false, // Will be determined after processing all clues
available: false,
};
})
);
// Determine which clues should be available
let firstUnavailableFound = false;
const finalClues = cluesWithStatus.map((clue, index, arr) => {
if (clue.found || clue.skipped) {
return { ...clue, available: true };
}
// If we haven't found an unavailable clue yet, this one is available
if (!firstUnavailableFound) {
firstUnavailableFound = true;
return { ...clue, available: true };