first commit
This commit is contained in:
25
app/api/rounds/route.ts
Normal file
25
app/api/rounds/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
|
||||
export async function GET() {
|
||||
const rounds = await db.round.findMany({ orderBy: { number: "asc" } });
|
||||
return NextResponse.json(rounds);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session || (session.user as any).role !== "ADMIN")
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
|
||||
const { number, name, deadline } = await req.json();
|
||||
|
||||
const existing = await db.round.findUnique({ where: { number } });
|
||||
if (existing) return NextResponse.json({ error: "این شماره دور قبلاً ثبت شده" }, { status: 400 });
|
||||
|
||||
const round = await db.round.create({
|
||||
data: { number, name, deadline: new Date(deadline) },
|
||||
});
|
||||
return NextResponse.json(round, { status: 201 });
|
||||
}
|
||||
Reference in New Issue
Block a user