Skip to content

Commit 6d3327a

Browse files
committed
FIX use api fetch
1 parent e7b69d8 commit 6d3327a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

app/src/composables/useApiFetch.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ import { FetchError } from 'ofetch'
2020

2121
// export const useApiFetch = useApiData
2222

23-
export type schemas = Components['schemas']
23+
function parseQuery(query: Record<string, any>, prefix: string = '') {
24+
let parsedQuery: any = {}
25+
for (const q in query) {
26+
const key = prefix ? `${prefix}[${q}]` : q
27+
if (typeof query[q] === 'object') {
28+
parsedQuery = { ...parsedQuery, ...parseQuery(query[q], key) }
29+
} else {
30+
parsedQuery[key] = query[q]
31+
}
32+
}
33+
return parsedQuery
34+
}
2435

2536
export function useApiFetch<P extends AllPaths<Paths>, M extends IgnoreCase<keyof Paths[`/${P}`] & HttpMethod>>(
2637
path: MaybeRefOrGetter<P>,
@@ -36,16 +47,19 @@ export function useApiFetch<P extends AllPaths<Paths>, M extends IgnoreCase<keyo
3647
/* @ts-ignore */
3748
body?: Paths[`/${P}`][Lowercase<M>]['requestBody']['content']['application/json'],
3849
): /* @ts-ignore */
39-
AsyncData<OpenApiResponse<Paths[`/${P}`][Lowercase<M>]> | undefined, FetchError<OpenApiError<Paths[`/${P}`][Lowercase<M>]>>> {
50+
AsyncData<OpenApiResponse<Paths[`/${P}`][Lowercase<M>]> | undefined, FetchError<OpenApiError<Paths[`/${P}`][Lowercase<M>]>>> {
51+
const query = parseQuery((opts as any)?.query || {})
4052
if (!body) {
4153
return useApiData(path, {
4254
...opts,
55+
query,
4356
cache: false,
4457
client: true,
4558
} as any)
4659
}
4760
return useApiData(path, {
4861
...opts,
62+
query,
4963
cache: false,
5064
client: true,
5165
body: {

0 commit comments

Comments
 (0)