Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
|
|
export async function listIssuesForUser(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
asMaster: boolean
|
|
) {
|
|
let query = supabase
|
|
.from("support_issues")
|
|
.select("*, leagues(name), competitions(name)")
|
|
.order("created_at", { ascending: false });
|
|
|
|
if (!asMaster) {
|
|
query = query.eq("submitted_by", userId);
|
|
}
|
|
|
|
const { data, error } = await query;
|
|
if (error) throw new Error(error.message);
|
|
return data;
|
|
}
|
|
|
|
export async function createIssue(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
input: {
|
|
leagueId: string;
|
|
competitionId?: string;
|
|
subject: string;
|
|
body: string;
|
|
}
|
|
) {
|
|
const { data, error } = await supabase
|
|
.from("support_issues")
|
|
.insert({
|
|
league_id: input.leagueId,
|
|
competition_id: input.competitionId ?? null,
|
|
submitted_by: userId,
|
|
subject: input.subject,
|
|
body: input.body,
|
|
})
|
|
.select()
|
|
.single();
|
|
if (error) throw new Error(error.message);
|
|
return data;
|
|
}
|
|
|
|
export async function updateIssueStatus(
|
|
supabase: SupabaseClient,
|
|
issueId: string,
|
|
status: "open" | "in_progress" | "resolved",
|
|
masterReply?: string
|
|
) {
|
|
const { error } = await supabase
|
|
.from("support_issues")
|
|
.update({
|
|
status,
|
|
...(masterReply !== undefined ? { master_reply: masterReply } : {}),
|
|
})
|
|
.eq("id", issueId);
|
|
if (error) throw new Error(error.message);
|
|
}
|