import { createClient } from "@/lib/supabase/server"; import { requireUser } from "@/lib/api/auth"; import { ApiError, apiError, apiSuccess, parseJson } from "@/lib/api/errors"; import * as masters from "@/lib/services/masters"; export async function GET( _request: Request, { params }: { params: Promise<{ leagueId: string }> } ) { try { const { leagueId } = await params; const supabase = await createClient(); await requireUser(supabase); const data = await masters.listLeagueMasters(supabase, leagueId); return apiSuccess(data); } catch (e) { return apiError(e); } } export async function POST( request: Request, { params }: { params: Promise<{ leagueId: string }> } ) { try { const { leagueId } = await params; const supabase = await createClient(); const user = await requireUser(supabase); const body = await parseJson<{ email: string }>(request); const targetId = await masters.getUserIdByEmail(supabase, body.email); if (!targetId) { throw new ApiError(404, "No user found with that email"); } await masters.assignLeagueMaster( supabase, leagueId, targetId, user.id ); return apiSuccess({ assigned: true }); } catch (e) { return apiError(e); } }