Skip to content

Commit

Permalink
missing params fix in getQuerystringSearchQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Faakhir30 committed Aug 30, 2024
1 parent 15387de commit a80af0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 1 addition & 3 deletions packages/client/src/restapi/querystring-search/get.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ describe('[GET] QuerystringSearch', () => {

const { result } = renderHook(
() =>
useQuery(
getQuerystringSearchQuery({ query: querystringSearchData.query }),
),
useQuery(getQuerystringSearchQuery({ data: querystringSearchData })),
{
wrapper: createWrapper(),
},
Expand Down
30 changes: 16 additions & 14 deletions packages/client/src/restapi/querystring-search/get.ts
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 }),
});

0 comments on commit a80af0f

Please sign in to comment.