fixed leaderboard, added feature to drop a team out of the teams table once it has hit 0 members, that check for members occurs when a user leaves a team. need to fix error with the timer in admin dashboard, make a separate page for it to be centrally run rather than be based on session instances.

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 17:19:15 +00:00
1 parent c098ad40bf
commit a762528494
5 files changed
+276 -108

No files matched your search

@@ -0,0 +1,61 @@
import { getToken } from "next-auth/jwt";
import { queryOne, run } from "@/lib/db";
export const dynamic = "force-dynamic"; // Disable caching
// Ensure the user is an admin
async function verifyAdmin(request) {
const token = await getToken({
req: request,
secret:
process.env.NEXTAUTH_SECRET ||
"your-fallback-secret-should-be-at-least-32-chars",
});
if (!token) {
return { authorized: false, error: "Unauthorized", status: 401 };
}
if (token.role !== "admin") {
return { authorized: false, error: "Admin access required", status: 403 };
}
return { authorized: true, token };
}
export async function POST(request, context) {
try {
// Verify admin access
const { authorized, error, status } = await verifyAdmin(request);
if (!authorized) {
return Response.json({ error }, { status });
}
const { teamId } = context.params;
// Validate teamId is a number
if (isNaN(parseInt(teamId))) {
return Response.json({ error: "Invalid team ID" }, { status: 400 });
}
// Check if team exists
const team = await queryOne("SELECT id FROM teams WHERE id = ?", [teamId]);
if (!team) {
return Response.json({ error: "Team not found" }, { status: 404 });
}
// Delete all clue progress for the team
await run("DELETE FROM team_clues WHERE team_id = ?", [teamId]);
return Response.json({
success: true,
message: "Team progress has been reset",
});
} catch (error) {
console.error("Admin reset team progress error:", error);
return Response.json(
{ error: "Failed to reset team progress: " + error.message },
{ status: 500 }
);
}
}