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 - } -}