fiddy/apps/web/lib/client/groups.ts
2026-02-11 23:45:15 -08:00

45 lines
1.3 KiB
TypeScript

import { fetchJson } from "@/lib/client/fetch-json";
import type { Group } from "@/lib/shared/types";
export async function groupsList() {
return fetchJson<{ groups: Group[] }>("/api/groups", { method: "GET" });
}
export async function groupsActive() {
return fetchJson<{ active: Group | null }>("/api/groups/active", { method: "GET" });
}
export async function groupsCreate(input: { name: string }) {
return fetchJson<{ group: { id: number; name: string; inviteCode: string } }>("/api/groups", {
method: "POST",
body: JSON.stringify(input)
});
}
export async function groupsJoin(input: { inviteCode: string }) {
return fetchJson<{ group: { id: number; name: string } }>("/api/groups/join", {
method: "POST",
body: JSON.stringify(input)
});
}
export async function groupsSetActive(input: { groupId: number }) {
return fetchJson<{ ok: true }>("/api/groups/active", {
method: "POST",
body: JSON.stringify(input)
});
}
export async function groupsRename(input: { name: string }) {
return fetchJson<{ ok: true }>("/api/groups/rename", {
method: "POST",
body: JSON.stringify(input)
});
}
export async function groupsDelete() {
return fetchJson<{ ok: true }>("/api/groups/delete", {
method: "POST"
});
}