mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
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:
1 parent
2236dceac9
commit
726121e105
18 files changed
+1504
-1192
No files matched your search
@@ -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 }
|
||||
|
||||
Reference in new issue
Block a user