From b852096972dcfe6a933581b0dcd6510c0618f8f2 Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Wed, 5 Nov 2025 12:23:59 +0800 Subject: [PATCH] Updated multi api function --- src/utils/functions/getApiMulti.ts | 18 ++++++++++++++++++ src/utils/functions/getMultiApi.ts | 22 ---------------------- 2 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 src/utils/functions/getApiMulti.ts delete mode 100644 src/utils/functions/getMultiApi.ts diff --git a/src/utils/functions/getApiMulti.ts b/src/utils/functions/getApiMulti.ts new file mode 100644 index 0000000..69d1b3e --- /dev/null +++ b/src/utils/functions/getApiMulti.ts @@ -0,0 +1,18 @@ +import { ofetch } from 'ofetch' + +const API = import.meta.env.VITE_BACKEND + +export default async (api: string, value?: any) => { + let fetch + try { + if (!value) { + fetch = await ofetch(API + api, { parseResponse: JSON.parse }) + } else { + fetch = await ofetch(API + `${api}/${value}`, { parseResponse: JSON.parse }) + } + + return fetch + } catch { + return {} + } +} diff --git a/src/utils/functions/getMultiApi.ts b/src/utils/functions/getMultiApi.ts deleted file mode 100644 index 695b81a..0000000 --- a/src/utils/functions/getMultiApi.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ofetch } from 'ofetch' - -const API = import.meta.env.VITE_BACKEND - -export default async (api: string) => { - try { - const fetchResponse = await ofetch(API + api) - - const resultObject: Record = {} - - for (let i = 1; i <= 10; i++) { - const propertyName = `result${i}` - if (fetchResponse.hasOwnProperty(propertyName)) { - resultObject[propertyName] = fetchResponse[propertyName] - } - } - - return resultObject - } catch { - return false - } -}