16 lines
675 B
TypeScript
16 lines
675 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { db } from "@/lib/db";
|
|
import { getApiUser } from "@/lib/apiAuth";
|
|
export async function POST(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
const apiUser = await getApiUser(req);
|
|
if (!apiUser || apiUser.role !== "ADMIN")
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
|
|
// غیرفعال کردن همه
|
|
await db.gameweek.updateMany({ data: { isActive: false } });
|
|
// فعال کردن این هفته
|
|
const gw = await db.gameweek.update({ where: { id }, data: { isActive: true } });
|
|
return NextResponse.json(gw);
|
|
}
|