24 lines
904 B
TypeScript
24 lines
904 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(req: 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 });
|
|
|
|
const lineups: Array<{ countryId: string; formation: string; playerIds: string[] }> = await req.json();
|
|
|
|
// حذف ترکیبهای قبلی
|
|
await db.matchLineup.deleteMany({ where: { matchId: params.id } });
|
|
|
|
for (const l of lineups) {
|
|
await db.matchLineup.create({
|
|
data: { matchId: params.id, countryId: l.countryId, formation: l.formation, playerIds: l.playerIds },
|
|
});
|
|
}
|
|
|
|
return NextResponse.json({ success: true });
|
|
}
|