From a9e4a1a6e140e27d95ddc6cb0cb129de2aabe424 Mon Sep 17 00:00:00 2001 From: Louise Wang Date: Sun, 28 Nov 2021 21:36:01 +0100 Subject: [PATCH] fix: fix parameters for get categories --- src/api/category.ts | 2 +- src/api/routes.ts | 2 +- src/hooks/category.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/category.ts b/src/api/category.ts index 9461748a..a81cda94 100644 --- a/src/api/category.ts +++ b/src/api/category.ts @@ -11,7 +11,7 @@ export const getCategoryTypes = async ({ API_HOST }: QueryClientConfig) => { return res.json(); }; -export const getCategories = async (typeId: UUID[], { API_HOST }: QueryClientConfig) => { +export const getCategories = async ({ API_HOST }: QueryClientConfig, typeId?: UUID[], ) => { console.log(typeId); console.log(buildGetCategoriesRoute(typeId)); const res = await fetch(`${API_HOST}/${buildGetCategoriesRoute(typeId)}`, DEFAULT_GET).then( diff --git a/src/api/routes.ts b/src/api/routes.ts index 944dcbb0..d3de6b78 100644 --- a/src/api/routes.ts +++ b/src/api/routes.ts @@ -140,7 +140,7 @@ export const buildRestoreItemsRoute = (ids: UUID[]) => )}`; export const GET_CATEGORY_TYPES_ROUTE = `${ITEMS_ROUTE}/category-types` -export const buildGetCategoriesRoute = (ids: UUID[]) => +export const buildGetCategoriesRoute = (ids?: UUID[]) => `${ITEMS_ROUTE}/categories?${qs.stringify( { type: ids }, { arrayFormat: 'repeat' } diff --git a/src/hooks/category.ts b/src/hooks/category.ts index c7db2787..8cd2bc9e 100644 --- a/src/hooks/category.ts +++ b/src/hooks/category.ts @@ -21,10 +21,10 @@ export default (queryConfig: QueryClientConfig) => { }); // get categories - const useCategories = (typeId: UUID[]) => + const useCategories = (typeId?: UUID[]) => useQuery({ queryKey: buildCategoriesKey(typeId), - queryFn: () => Api.getCategories(typeId, queryConfig).then((data) => List(data)), + queryFn: () => Api.getCategories(queryConfig, typeId).then((data) => List(data)), ...defaultOptions, });