From b695d36e566a307014d3153e96aa5a5d8ebe5e7f Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Tue, 21 Oct 2025 11:44:42 +0800 Subject: [PATCH] New fetch for multiple data --- src/utils/functions/fetchMultiApi.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/utils/functions/fetchMultiApi.ts diff --git a/src/utils/functions/fetchMultiApi.ts b/src/utils/functions/fetchMultiApi.ts new file mode 100644 index 0000000..695b81a --- /dev/null +++ b/src/utils/functions/fetchMultiApi.ts @@ -0,0 +1,22 @@ +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 + } +}