diff --git a/packages/client/src/restapi/querystring-search/get.test.tsx b/packages/client/src/restapi/querystring-search/get.test.tsx index 326973aa4bc..2db11079cb6 100644 --- a/packages/client/src/restapi/querystring-search/get.test.tsx +++ b/packages/client/src/restapi/querystring-search/get.test.tsx @@ -45,9 +45,7 @@ describe('[GET] QuerystringSearch', () => { const { result } = renderHook( () => - useQuery( - getQuerystringSearchQuery({ query: querystringSearchData.query }), - ), + useQuery(getQuerystringSearchQuery({ data: querystringSearchData })), { wrapper: createWrapper(), }, diff --git a/packages/client/src/restapi/querystring-search/get.ts b/packages/client/src/restapi/querystring-search/get.ts index 926453dfbde..e1e1ac6e904 100644 --- a/packages/client/src/restapi/querystring-search/get.ts +++ b/packages/client/src/restapi/querystring-search/get.ts @@ -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; export const getQuerystringSearch = async ({ - query, + data, config, }: QuerystringSearchArgs): Promise => { - 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 }), });