Yaltopia-FIFA/actions/teams.ts
Kirubel-Kibru-Yaltopia 89440985f1
Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
x
2026-05-24 21:46:10 +03:00

65 lines
1.6 KiB
TypeScript

"use server";
import { revalidatePath } from "next/cache";
import { createClient } from "@/lib/supabase/server";
import * as teams from "@/lib/services/teams";
import * as players from "@/lib/services/players";
export async function updateTeamProfile(
teamId: string,
data: { home_stadium_name?: string; logo_path?: string }
) {
const supabase = await createClient();
await teams.updateTeam(supabase, teamId, data);
revalidatePath("/leagues");
}
export async function setTeamAvailability(
teamId: string,
windows: { day_of_week: number; start_time?: string; end_time?: string }[]
) {
const supabase = await createClient();
await teams.setAvailability(supabase, teamId, windows);
revalidatePath("/leagues");
}
export async function addToRoster(
teamId: string,
competitionId: string,
playerId: string
) {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) throw new Error("Unauthorized");
await players.addToRoster(supabase, user.id, {
teamId,
competitionId,
playerId,
});
revalidatePath("/leagues");
}
export async function registerTransfer(
competitionId: string,
playerId: string,
fromTeamId: string,
toTeamId: string
) {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) throw new Error("Unauthorized");
await players.registerTransfer(supabase, user.id, {
competitionId,
playerId,
fromTeamId,
toTeamId,
});
revalidatePath("/leagues");
}