57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import type { ChannelResponse, GuildResponse, MessageResponse } from "~/types/interfaces";
|
|
|
|
export const useApi = () => {
|
|
async function fetchGuilds(guildId: string): Promise<GuildResponse[] | undefined> {
|
|
return await fetchWithApi(`/guilds`);
|
|
}
|
|
|
|
async function fetchGuild(guildId: string): Promise<GuildResponse | undefined> {
|
|
return await fetchWithApi(`/guilds/${guildId}`);
|
|
}
|
|
|
|
async function fetchChannels(guildId: string): Promise<ChannelResponse[] | undefined> {
|
|
return await fetchWithApi(`/guilds/${guildId}/channels`);
|
|
}
|
|
|
|
async function fetchChannel(channelId: string): Promise<ChannelResponse | undefined> {
|
|
return await fetchWithApi(`/channels/${channelId}`)
|
|
}
|
|
|
|
|
|
async function fetchMembers(guildId: string) {
|
|
return await fetchWithApi(`/guilds/${guildId}/members`);
|
|
}
|
|
|
|
async function fetchMember(guildId: string, memberId: string) {
|
|
return await fetchWithApi(`/guilds/${guildId}/members/${memberId}`);
|
|
}
|
|
|
|
async function fetchUsers(userId: string) {
|
|
return await fetchWithApi(`/users`);
|
|
}
|
|
|
|
async function fetchUser(userId: string) {
|
|
return await fetchWithApi(`/users/${userId}`);
|
|
}
|
|
|
|
async function fetchMessages(channelId: string): Promise<MessageResponse[] | undefined> {
|
|
return await fetchWithApi(`/channels/${channelId}/messages`);
|
|
}
|
|
|
|
async function fetchMessage(channelId: string, messageId: string): Promise<MessageResponse | undefined> {
|
|
return await fetchWithApi(`/channels/${channelId}/messages/${messageId}`);
|
|
}
|
|
|
|
return {
|
|
fetchGuilds,
|
|
fetchGuild,
|
|
fetchChannels,
|
|
fetchChannel,
|
|
fetchMembers,
|
|
fetchMember,
|
|
fetchUsers,
|
|
fetchUser,
|
|
fetchMessages,
|
|
fetchMessage
|
|
}
|
|
}
|