Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { createClient } from "@/lib/supabase/server";
|
|
import { requireUser } from "@/lib/api/auth";
|
|
import { ApiError, apiError, apiSuccess, parseJson } from "@/lib/api/errors";
|
|
import * as matches from "@/lib/services/matches";
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ matchId: string }> }
|
|
) {
|
|
try {
|
|
const { matchId } = await params;
|
|
const supabase = await createClient();
|
|
await requireUser(supabase);
|
|
const body = await parseJson<{
|
|
action: "propose" | "sign";
|
|
scheduledAt?: string;
|
|
teamId?: string;
|
|
}>(request);
|
|
|
|
if (body.action === "propose") {
|
|
if (!body.scheduledAt) throw new ApiError(400, "scheduledAt required");
|
|
await matches.proposeSchedule(supabase, matchId, body.scheduledAt);
|
|
} else if (body.action === "sign") {
|
|
if (!body.teamId) throw new ApiError(400, "teamId required");
|
|
await matches.signSchedule(supabase, matchId, body.teamId);
|
|
} else {
|
|
throw new ApiError(400, "action must be propose or sign");
|
|
}
|
|
|
|
return apiSuccess({ ok: true });
|
|
} catch (e) {
|
|
return apiError(e);
|
|
}
|
|
}
|