Updated multi api function
This commit is contained in:
parent
b19acd6343
commit
b852096972
2 changed files with 18 additions and 22 deletions
18
src/utils/functions/getApiMulti.ts
Normal file
18
src/utils/functions/getApiMulti.ts
Normal file
|
|
@ -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 {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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<string, any> = {}
|
|
||||||
|
|
||||||
for (let i = 1; i <= 10; i++) {
|
|
||||||
const propertyName = `result${i}`
|
|
||||||
if (fetchResponse.hasOwnProperty(propertyName)) {
|
|
||||||
resultObject[propertyName] = fetchResponse[propertyName]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultObject
|
|
||||||
} catch {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue