From 115b7d834118aa944700f6242b02c5031be130ce Mon Sep 17 00:00:00 2001 From: SauceyRed Date: Sat, 31 May 2025 16:31:40 +0200 Subject: [PATCH] feat: remove old utils in favor of api composable --- composables/api.ts | 57 ++++++++++++++++++++++++++++++++++++++++++++ utils/fetchMember.ts | 6 ----- utils/fetchUser.ts | 6 ----- 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 composables/api.ts delete mode 100644 utils/fetchMember.ts delete mode 100644 utils/fetchUser.ts diff --git a/composables/api.ts b/composables/api.ts new file mode 100644 index 0000000..f1ac525 --- /dev/null +++ b/composables/api.ts @@ -0,0 +1,57 @@ +import type { ChannelResponse, GuildResponse, MessageResponse } from "~/types/interfaces"; + +export const useApi = () => { + async function fetchGuilds(guildId: string): Promise { + return await fetchWithApi(`/guilds`); + } + + async function fetchGuild(guildId: string): Promise { + return await fetchWithApi(`/guilds/${guildId}`); + } + + async function fetchChannels(guildId: string): Promise { + return await fetchWithApi(`/guilds/${guildId}/channels`); + } + + async function fetchChannel(channelId: string): Promise { + 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 { + return await fetchWithApi(`/channels/${channelId}/messages`); + } + + async function fetchMessage(channelId: string, messageId: string): Promise { + return await fetchWithApi(`/channels/${channelId}/messages/${messageId}`); + } + + return { + fetchGuilds, + fetchGuild, + fetchChannels, + fetchChannel, + fetchMembers, + fetchMember, + fetchUsers, + fetchUser, + fetchMessages, + fetchMessage + } +} diff --git a/utils/fetchMember.ts b/utils/fetchMember.ts deleted file mode 100644 index 8f4a9e4..0000000 --- a/utils/fetchMember.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { UserResponse } from "~/types/interfaces" - -export default async (serverId: string, memberId: string): Promise => { - const user = await fetchWithApi(`/guilds/${serverId}/members/${memberId}`) as UserResponse; - return user; -} diff --git a/utils/fetchUser.ts b/utils/fetchUser.ts deleted file mode 100644 index d509fe0..0000000 --- a/utils/fetchUser.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { UserResponse } from "~/types/interfaces" - -export default async (serverId: string, userId: string): Promise => { - const user = await fetchWithApi(`/users/${userId}`) as UserResponse; - return user; -}