first commit

This commit is contained in:
a.alinaghipour
2026-04-05 15:53:20 +03:30
commit aa9ed69dd2
96 changed files with 7721 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { getFormationChangeIssues, FORMATIONS } from "@/lib/teamValidation";
export async function PUT(req: NextRequest) {
const session = await getServerSession(authOptions);
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const { formation } = await req.json();
if (!FORMATIONS[formation]) return NextResponse.json({ error: "ترکیب نامعتبر" }, { status: 400 });
const team = await db.team.findUnique({
where: { userId: (session.user as any).id },
include: { players: { include: { player: true } } },
});
if (!team) return NextResponse.json({ error: "تیم پیدا نشد" }, { status: 404 });
const playerList = team.players.map((tp) => ({ position: tp.player.position, isBench: tp.isBench }));
const issues = getFormationChangeIssues(playerList, team.formation, formation);
if (issues.length > 0) {
return NextResponse.json({ error: issues.join(" | "), issues }, { status: 400 });
}
const updated = await db.team.update({ where: { id: team.id }, data: { formation } });
return NextResponse.json(updated);
}