From a1bae7ced3bcc8cafaf1dfad23cb04a3d626f6a7 Mon Sep 17 00:00:00 2001 From: NaNoMelo Date: Sat, 12 Oct 2024 18:48:06 +0200 Subject: [PATCH] fix empty options in paginated with typescript --- core/static/webpack/utils/api.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/static/webpack/utils/api.ts b/core/static/webpack/utils/api.ts index a2c872c7..72df568b 100644 --- a/core/static/webpack/utils/api.ts +++ b/core/static/webpack/utils/api.ts @@ -27,10 +27,12 @@ export const paginated = async ( options?: PaginatedRequest, ) => { const maxPerPage = 199; - options.query.page_size = maxPerPage; - options.query.page = 1; + const queryParams = options ?? {}; + queryParams.query = queryParams.query ?? {}; + queryParams.query.page_size = maxPerPage; + queryParams.query.page = 1; - const firstPage = (await endpoint(options)).data; + const firstPage = (await endpoint(queryParams)).data; const results = firstPage.results; const nbElements = firstPage.count; @@ -39,7 +41,7 @@ export const paginated = async ( if (nbPages > 1) { const promises: Promise[] = []; for (let i = 2; i <= nbPages; i++) { - const nextPage = structuredClone(options); + const nextPage = structuredClone(queryParams); nextPage.query.page = i; promises.push(endpoint(nextPage).then((res) => res.data.results)); }