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

34
app/api/team/route.ts Normal file
View File

@@ -0,0 +1,34 @@
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 session = await getServerSession(authOptions);
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const team = await db.team.findUnique({
where: { userId: (session.user as any).id },
include: {
players: {
include: { player: true },
},
},
});
return NextResponse.json(team);
}
export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const { name } = await req.json();
const userId = (session.user as any).id;
const existing = await db.team.findUnique({ where: { userId } });
if (existing) return NextResponse.json({ error: "Team already exists" }, { status: 400 });
const team = await db.team.create({ data: { name, userId } });
return NextResponse.json(team, { status: 201 });
}