Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
39 lines
996 B
TypeScript
39 lines
996 B
TypeScript
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
|
|
export async function assignLeagueMaster(
|
|
supabase: SupabaseClient,
|
|
leagueId: string,
|
|
userId: string,
|
|
assignedBy: string
|
|
) {
|
|
const { error } = await supabase.from("league_masters").upsert({
|
|
league_id: leagueId,
|
|
user_id: userId,
|
|
assigned_by: assignedBy,
|
|
});
|
|
if (error) throw new Error(error.message);
|
|
}
|
|
|
|
export async function listLeagueMasters(
|
|
supabase: SupabaseClient,
|
|
leagueId: string
|
|
) {
|
|
const { data, error } = await supabase
|
|
.from("league_masters")
|
|
.select("user_id, profiles(display_name)")
|
|
.eq("league_id", leagueId);
|
|
if (error) throw new Error(error.message);
|
|
return data;
|
|
}
|
|
|
|
export async function getUserIdByEmail(
|
|
supabase: SupabaseClient,
|
|
email: string
|
|
) {
|
|
const { data, error } = await supabase.rpc("get_user_id_by_email", {
|
|
p_email: email,
|
|
});
|
|
if (error) throw new Error(error.message);
|
|
return data as string | null;
|
|
}
|