Add hunts table and default row; improve error handling and UI for team management

This commit is contained in:
bobbert committed 2025-03-12 15:48:35 +00:00
1 parent cd9c106ba1
commit a6ed24b2e6
8 files changed
+156 -52

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { getServerSession } from "next-auth/next";
import { authOptions } from "../auth/[...nextauth]/route";
import { run } from "@/lib/db";
export async function POST(request) {
const session = await getServerSession(authOptions);
if (!session || session.user.role !== "admin") {
return new Response(JSON.stringify({ error: "Unauthorized" }), {
status: 401,
});
}
try {
// Add a WHERE clause or provide an ID if you're updating a specific hunt record
await run("UPDATE hunts SET active = 1, start_time = NOW() WHERE id = ?", [1]);
// Or if you just have one hunt record: "UPDATE hunts SET active = 1, start_time = NOW()"
return new Response(JSON.stringify({ success: true }), { status: 200 });
} catch (err) {
console.error("Hunt start error:", err); // Add logging for better debugging
return new Response(JSON.stringify({ error: err.message }), {
status: 500,
});
}
}