mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-24 18:14:22 +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,
|
options?: PaginatedRequest,
|
||||||
) => {
|
) => {
|
||||||
const maxPerPage = 199;
|
const maxPerPage = 199;
|
||||||
options.query.page_size = maxPerPage;
|
const queryParams = options ?? {};
|
||||||
options.query.page = 1;
|
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 results = firstPage.results;
|
||||||
|
|
||||||
const nbElements = firstPage.count;
|
const nbElements = firstPage.count;
|
||||||
@ -39,7 +41,7 @@ export const paginated = async <T>(
|
|||||||
if (nbPages > 1) {
|
if (nbPages > 1) {
|
||||||
const promises: Promise<T[]>[] = [];
|
const promises: Promise<T[]>[] = [];
|
||||||
for (let i = 2; i <= nbPages; i++) {
|
for (let i = 2; i <= nbPages; i++) {
|
||||||
const nextPage = structuredClone(options);
|
const nextPage = structuredClone(queryParams);
|
||||||
nextPage.query.page = i;
|
nextPage.query.page = i;
|
||||||
promises.push(endpoint(nextPage).then((res) => res.data.results));
|
promises.push(endpoint(nextPage).then((res) => res.data.results));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user