Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
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 GET(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ competitionId: string }> }
|
|
) {
|
|
try {
|
|
const { competitionId } = await params;
|
|
const supabase = await createClient();
|
|
await requireUser(supabase);
|
|
const data = await players.listTransfers(supabase, competitionId);
|
|
return apiSuccess(data);
|
|
} catch (e) {
|
|
return apiError(e);
|
|
}
|
|
}
|
|
|
|
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<{
|
|
playerId: string;
|
|
fromTeamId: string;
|
|
toTeamId: string;
|
|
}>(request);
|
|
await players.registerTransfer(supabase, user.id, {
|
|
competitionId,
|
|
...body,
|
|
});
|
|
return apiSuccess({ transferred: true });
|
|
} catch (e) {
|
|
return apiError(e);
|
|
}
|
|
}
|