fixing map timing errors and still trying to make leaderboard and clues pages.

Grey = cant click
Red = current
Green = complete
blue = skipped?

Need to add Clue page Need to fix Leaderboard.
This commit is contained in:
bobbert committed 2025-03-15 16:52:50 +00:00
1 parent 16319f1333
commit 30d88407a0
8 files changed
+597 -169

No files matched your search

+3 -1
View File
@@ -24,7 +24,7 @@ export async function GET(request) {
);
}
// Get all clues
// Get all clues with explicit ordering to ensure consistency
const clues = await query(`
SELECT id, title, description, location, x_coord, y_coord
FROM clues
@@ -46,6 +46,8 @@ export async function GET(request) {
})
);
console.log(`Returning ${cluesWithStatus.length} clues`);
return Response.json(cluesWithStatus, {
headers: {
"Cache-Control": "no-store, no-cache, must-revalidate",
+75 -7
View File
@@ -1,12 +1,80 @@
import { query } from '../../../lib/db';
import { getToken } from "next-auth/jwt";
import { queryOne, run } from "@/lib/db";
export const dynamic = "force-dynamic"; // Disable caching
export async function POST(request) {
const { clueId, teamId } = await request.json();
try {
const token = await getToken({
req: request,
secret:
process.env.NEXTAUTH_SECRET ||
"your-fallback-secret-should-be-at-least-32-chars",
});
await query('UPDATE clues SET found = TRUE WHERE id = ? AND team_id = ?', [
clueId,
teamId,
if (!token) {
return Response.json({ error: "Unauthorized" }, { status: 401 });
}
// Check if user has a team
if (!token.teamId) {
return Response.json(
{ error: "You must be part of a team to mark clues as found" },
{ status: 403 }
);
}
const { clueId } = await request.json();
// Validate clueId is a number
if (!clueId || isNaN(parseInt(clueId))) {
return Response.json({ error: "Invalid clue ID" }, { status: 400 });
}
// Ensure the team_clues table exists
await run(`
CREATE TABLE IF NOT EXISTS team_clues (
team_id INTEGER NOT NULL,
clue_id INTEGER NOT NULL,
found_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (team_id, clue_id),
FOREIGN KEY (team_id) REFERENCES teams(id),
FOREIGN KEY (clue_id) REFERENCES clues(id)
)
`);
// Check if this clue is already found
const found = await queryOne(
"SELECT 1 FROM team_clues WHERE team_id = ? AND clue_id = ?",
[token.teamId, clueId]
);
// If already found, return success with a message
if (found) {
return Response.json({
success: true,
message: "This clue was already found",
alreadyFound: true,
});
}
// Record that the team found this clue
await run("INSERT INTO team_clues (team_id, clue_id) VALUES (?, ?)", [
token.teamId,
clueId,
]);
return Response.json({ message: 'Clue marked as found' });
}
return Response.json({
success: true,
message: "Clue marked as found successfully",
clueId: clueId,
teamId: token.teamId,
});
} catch (error) {
console.error("Error marking clue as found:", error);
return Response.json(
{ error: "Failed to mark clue as found: " + error.message },
{ status: 500 }
);
}
}