-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
missing params fix in getQuerystringSearchQuery
- Loading branch information
Showing
2 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import { apiRequest, ApiRequestParams } from '../../API'; | ||
import { PloneClientConfig } from '../../validation/config'; | ||
import { PloneClientConfigSchema } from '../../validation/config'; | ||
import { z } from 'zod'; | ||
import { querystringSearchDataSchema as getQuerystringSearchSchema } from '../../validation/querystring-search'; | ||
import { QuerystringSearchResponse as GetQuerystringSearchResponse } from '@plone/types'; | ||
|
||
export type QuerystringSearchArgs = z.infer< | ||
typeof getQuerystringSearchSchema | ||
> & { | ||
config: PloneClientConfig; | ||
}; | ||
export const QuerystringSearchArgs = z.object({ | ||
data: getQuerystringSearchSchema, | ||
config: PloneClientConfigSchema, | ||
}); | ||
|
||
export type QuerystringSearchArgs = z.infer<typeof QuerystringSearchArgs>; | ||
|
||
export const getQuerystringSearch = async ({ | ||
query, | ||
data, | ||
config, | ||
}: QuerystringSearchArgs): Promise<GetQuerystringSearchResponse> => { | ||
const validatedArgs = getQuerystringSearchSchema.parse({ | ||
query, | ||
const validatedArgs = QuerystringSearchArgs.parse({ | ||
data, | ||
config, | ||
}); | ||
|
||
const queryObject = { query: validatedArgs.query }; | ||
const queryObject = { query: validatedArgs.data.query }; | ||
const querystring = JSON.stringify(queryObject); | ||
const encodedQuery = encodeURIComponent(querystring); | ||
|
||
const options: ApiRequestParams = { | ||
config, | ||
params: { | ||
...data, | ||
...(encodedQuery && { query: encodedQuery }), | ||
}, | ||
config: validatedArgs.config, | ||
}; | ||
|
||
return apiRequest('get', '/@querystring-search', options); | ||
}; | ||
|
||
export const getQuerystringSearchQuery = ({ | ||
query, | ||
data, | ||
config, | ||
}: QuerystringSearchArgs) => ({ | ||
queryKey: ['get', 'querystringSearch'], | ||
queryFn: () => getQuerystringSearch({ query, config }), | ||
queryFn: () => getQuerystringSearch({ data, config }), | ||
}); |