Files
football-next/app/api/admin/matches/[id]/events/route.ts
2026-05-13 15:46:27 +03:30

18 lines
689 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 });
const { playerId, type, minute, extraInfo } = await req.json();
const event = await db.matchEvent.create({
data: { matchId: id, playerId, type, minute: minute ?? null, extraInfo: extraInfo || null },
});
return NextResponse.json(event, { status: 201 });
}