FIXED CLUES! all that needs to be done is manually adding circle buttons and hiding/showing feature through API.. maybe fixing QR scanner

This commit is contained in:
bobbert committed 2025-03-17 10:42:33 +00:00
1 parent 2236dceac9
commit 726121e105
18 files changed
+1504 -1192

No files matched your search

+3 -45
View File
@@ -24,6 +24,7 @@ export async function GET(request, context) {
);
}
// Get the clueId directly from the params
const { clueId } = context.params;
// Validate clueId is a number
@@ -31,7 +32,7 @@ export async function GET(request, context) {
return Response.json({ error: "Invalid clue ID" }, { status: 400 });
}
// Get the specific clue - removed coordinates
// Get the specific clue
const clue = await queryOne(
"SELECT id, title, description, location FROM clues WHERE id = ?",
[clueId]
@@ -41,54 +42,12 @@ export async function GET(request, context) {
return Response.json({ error: "Clue not found" }, { status: 404 });
}
// Get timestamp parameter to determine if this is a refresh call
const timestamp = request.nextUrl?.searchParams?.get("t");
const isRefresh = timestamp && !isNaN(parseInt(timestamp));
// Check if this team has found this clue before
const found = await queryOne(
"SELECT * FROM team_clues WHERE team_id = ? AND clue_id = ?",
[token.teamId, clueId]
);
// Only mark as "foundNow" if:
// 1. The clue was not found before
// 2. This is not a refresh request (or we can't determine)
// 3. The user is not an admin (admins don't need "foundNow" animations)
let foundNow = false;
if (!found && (!isRefresh || token.role !== "admin")) {
try {
// First ensure the team_clues table exists
await queryOne(`
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)
)
`);
// Record that the team found this clue
await queryOne(
"INSERT INTO team_clues (team_id, clue_id) VALUES (?, ?)",
[token.teamId, clueId]
);
// Set foundNow flag for non-admin users only
foundNow = token.role !== "admin";
console.log(
`Clue ${clueId} marked as found for team ${token.teamId}, foundNow=${foundNow}`
);
} catch (err) {
console.error("Error marking clue as found:", err);
// Continue even if there's an error recording the find
}
}
// Add different cache headers for admins vs regular users
const cacheHeaders =
token.role === "admin"
@@ -106,8 +65,7 @@ export async function GET(request, context) {
return Response.json(
{
...clue,
found: true, // Always return as found since the user is viewing it
foundNow, // Only true during initial discovery for non-admins
found: !!found, // Only mark as found if it was previously found
isAdmin: token.role === "admin", // Add flag so client knows user is admin
},
{ headers: cacheHeaders }
+29 -22
View File
@@ -1,5 +1,5 @@
import { query, queryOne } from "@/lib/db";
import { getToken } from "next-auth/jwt";
import { queryOne, run } from "@/lib/db";
export const dynamic = "force-dynamic"; // Disable caching
@@ -24,15 +24,36 @@ export async function POST(request) {
);
}
// Parse request body
const { clueId } = await request.json();
// Validate clueId is a number
if (!clueId || isNaN(parseInt(clueId))) {
if (isNaN(parseInt(clueId))) {
return Response.json({ error: "Invalid clue ID" }, { status: 400 });
}
// Ensure the team_clues table exists
await run(`
// Check if clue exists
const clue = await queryOne("SELECT id FROM clues WHERE id = ?", [clueId]);
if (!clue) {
return Response.json({ error: "Clue not found" }, { status: 404 });
}
// Check if clue was already found
const alreadyFound = await queryOne(
"SELECT * FROM team_clues WHERE team_id = ? AND clue_id = ?",
[token.teamId, clueId]
);
if (alreadyFound) {
return Response.json({
success: true,
message: "This clue was already marked as found",
alreadyFound: true,
});
}
// Create team_clues table if it doesn't exist
await queryOne(`
CREATE TABLE IF NOT EXISTS team_clues (
team_id INTEGER NOT NULL,
clue_id INTEGER NOT NULL,
@@ -43,32 +64,18 @@ export async function POST(request) {
)
`);
// 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 (?, ?)", [
await queryOne("INSERT INTO team_clues (team_id, clue_id) VALUES (?, ?)", [
token.teamId,
clueId,
]);
console.log(`Clue ${clueId} marked as found for team ${token.teamId}`);
// Return successful response
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);