76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
import { fetchJson } from "@/lib/client/fetch-json";
|
|
|
|
export type GroupRole = "MEMBER" | "GROUP_ADMIN" | "GROUP_OWNER";
|
|
|
|
export type GroupMember = {
|
|
userId: number;
|
|
email: string;
|
|
displayName: string | null;
|
|
role: GroupRole;
|
|
joinedAt: string;
|
|
lastLoginAt: string | null;
|
|
lastActiveAt: string | null;
|
|
};
|
|
|
|
export type JoinRequest = {
|
|
id: number;
|
|
groupId: number;
|
|
userId: number;
|
|
email: string;
|
|
displayName: string | null;
|
|
status: "PENDING" | "APPROVED" | "DENIED" | "CANCELED";
|
|
createdAt: string;
|
|
};
|
|
|
|
export async function groupMembersList() {
|
|
return fetchJson<{ members: GroupMember[]; requests: JoinRequest[]; currentUserId: number }>("/api/groups/members", { method: "GET" });
|
|
}
|
|
|
|
export async function groupMembersApprove(input: { userId: number; requestId?: number }) {
|
|
return fetchJson<{ ok: true }>("/api/groups/members/approve", {
|
|
method: "POST",
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export async function groupMembersDeny(input: { userId: number }) {
|
|
return fetchJson<{ ok: true }>("/api/groups/members/deny", {
|
|
method: "POST",
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export async function groupMembersKick(input: { userId: number }) {
|
|
return fetchJson<{ ok: true }>("/api/groups/members/kick", {
|
|
method: "POST",
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export async function groupMembersPromote(input: { userId: number }) {
|
|
return fetchJson<{ ok: true }>("/api/groups/members/promote", {
|
|
method: "POST",
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export async function groupMembersDemote(input: { userId: number }) {
|
|
return fetchJson<{ ok: true }>("/api/groups/members/demote", {
|
|
method: "POST",
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export async function groupMembersLeave() {
|
|
return fetchJson<{ ok: true }>("/api/groups/members/leave", {
|
|
method: "POST"
|
|
});
|
|
}
|
|
|
|
export async function groupMembersTransferOwner(input: { userId: number }) {
|
|
return fetchJson<{ ok: true }>("/api/groups/members/transfer-owner", {
|
|
method: "POST",
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|