mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-25 09:11:13 +00:00
fix empty options in paginated with typescript
This commit is contained in:
parent
1c774aa4a0
commit
a1bae7ced3
@ -27,10 +27,12 @@ export const paginated = async <T>(
|
||||
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 <T>(
|
||||
if (nbPages > 1) {
|
||||
const promises: Promise<T[]>[] = [];
|
||||
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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user