mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
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:
1 parent
4cd449c0cf
commit
8fd2cabbe0
10 files changed
+226
-136
No files matched your search
@@ -3,7 +3,6 @@ import { queryOne, run } from "@/lib/db";
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
// Verify user authentication
|
||||
const token = await getToken({
|
||||
req: request,
|
||||
secret:
|
||||
@@ -15,20 +14,16 @@ export async function POST(request) {
|
||||
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
// Get user ID from token
|
||||
const userId = token.id;
|
||||
|
||||
// Get team name from request body
|
||||
const { name } = await request.json();
|
||||
|
||||
if (!name || !name.trim()) {
|
||||
return Response.json({ error: "Team name is required" }, { status: 400 });
|
||||
}
|
||||
|
||||
// Generate a unique team code
|
||||
const code = generateTeamCode();
|
||||
|
||||
// Create teams table if it doesn't exist
|
||||
await run(`
|
||||
CREATE TABLE IF NOT EXISTS teams (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -38,7 +33,6 @@ export async function POST(request) {
|
||||
)
|
||||
`);
|
||||
|
||||
// Check if team name already exists
|
||||
const existingTeam = await queryOne("SELECT id FROM teams WHERE name = ?", [
|
||||
name,
|
||||
]);
|
||||
@@ -50,7 +44,6 @@ export async function POST(request) {
|
||||
);
|
||||
}
|
||||
|
||||
// Insert team
|
||||
const result = await run("INSERT INTO teams (name, code) VALUES (?, ?)", [
|
||||
name,
|
||||
code,
|
||||
@@ -61,10 +54,8 @@ export async function POST(request) {
|
||||
throw new Error("Failed to create team - no ID returned");
|
||||
}
|
||||
|
||||
// Update the user's team_id
|
||||
await run("UPDATE users SET team_id = ? WHERE id = ?", [teamId, userId]);
|
||||
|
||||
// Return success with team info
|
||||
return Response.json({
|
||||
success: true,
|
||||
teamId,
|
||||
|
||||
Reference in new issue
Block a user