Add Tournament form

This commit is contained in:
Owen Rees
2023-08-29 22:55:22 +02:00
parent 419a3dd0c0
commit d33d447f90
21 changed files with 924 additions and 110 deletions
+53
View File
@@ -0,0 +1,53 @@
import clientPromise from "@/lib/mongodb";
import { NextResponse } from "next/server";
import { errorLog } from "@/utils/logger";
export async function POST(req: Request) {
const {
address,
town,
department,
tournament,
url,
time_control,
norm_tournament,
date,
coordinates,
country,
} = await req.json();
try {
const client = await clientPromise;
const db = client.db("tournamentsFranceDB").collection("tournaments");
const tournamentData = {
address,
town,
department,
tournament,
url,
time_control,
norm_tournament,
date,
coordinates,
country,
entry_method: "manual",
pending: true,
};
const result = await db.insertOne(tournamentData);
if (result.insertedId) {
return new NextResponse(
JSON.stringify({ success: "Tournament added to DB as pending" }),
{ status: 201, headers: { "Content-Type": "application/json" } },
);
}
} catch (error) {
errorLog(error);
return new NextResponse(
JSON.stringify({ error: "Failed to insert tournament data" }),
{ status: 500, headers: { "Content-Type": "application/json" } },
);
}
}