17 lines
717 B
TypeScript
17 lines
717 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { db } from "@/lib/db";
|
|
import { getServerSession } from "next-auth";
|
|
import { authOptions } from "@/lib/auth";
|
|
|
|
export async function POST(_: NextRequest, { params }: { params: { id: string } }) {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session || (session.user as any).role !== "ADMIN")
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
|
|
// غیرفعال کردن همه
|
|
await db.gameweek.updateMany({ data: { isActive: false } });
|
|
// فعال کردن این هفته
|
|
const gw = await db.gameweek.update({ where: { id: params.id }, data: { isActive: true } });
|
|
return NextResponse.json(gw);
|
|
}
|