Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
25 lines
803 B
TypeScript
25 lines
803 B
TypeScript
import { createClient } from "@/lib/supabase/server";
|
|
import { requireUser } from "@/lib/api/auth";
|
|
import { apiError, apiSuccess, parseJson } from "@/lib/api/errors";
|
|
import * as players from "@/lib/services/players";
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ competitionId: string }> }
|
|
) {
|
|
try {
|
|
const { competitionId } = await params;
|
|
const supabase = await createClient();
|
|
const user = await requireUser(supabase);
|
|
const body = await parseJson<{ teamId: string; playerId: string }>(request);
|
|
await players.addToRoster(supabase, user.id, {
|
|
teamId: body.teamId,
|
|
competitionId,
|
|
playerId: body.playerId,
|
|
});
|
|
return apiSuccess({ added: true });
|
|
} catch (e) {
|
|
return apiError(e);
|
|
}
|
|
}
|