feat: remove old utils in favor of api composable
This commit is contained in:
parent
310b1cc2df
commit
115b7d8341
3 changed files with 57 additions and 12 deletions
57
composables/api.ts
Normal file
57
composables/api.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue