forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroupApi.ts
More file actions
31 lines (26 loc) · 994 Bytes
/
Copy pathgroupApi.ts
File metadata and controls
31 lines (26 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { Group, ApiResponse } from "../types/split-group";
const API_BASE = "/api/groups";
export async function fetchGroups(): Promise<ApiResponse<Group[]>> {
const res = await fetch(API_BASE);
return res.json();
}
export async function createGroup(name: string, members: string[]): Promise<ApiResponse<Group>> {
const res = await fetch(API_BASE, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name, members }),
});
return res.json();
}
export async function addMember(groupId: string, member: string): Promise<ApiResponse<Group>> {
const res = await fetch(`${API_BASE}/${groupId}/members`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ member }),
});
return res.json();
}
export async function startSplit(groupId: string): Promise<ApiResponse<Group>> {
const res = await fetch(`${API_BASE}/${groupId}/split`, { method: "POST" });
return res.json();
}