feature/backend-rewrite #2

Open
kamil wants to merge 236 commits from feature/backend-rewrite into main
Showing only changes of commit b0547c1b43 - Show all commits

View File

@@ -132,13 +132,28 @@ interface PBList<T> {
}
async function listAll<T>(collection: string, filter = '', sort = ''): Promise<T[]> {
const params = new URLSearchParams({ perPage: '500' });
const perPage = 500;
const params = new URLSearchParams({ perPage: String(perPage), page: '1' });
if (filter) params.set('filter', filter);
if (sort) params.set('sort', sort);
const data = await pbGet<PBList<T>>(
const first = await pbGet<PBList<T>>(
`/api/collections/${collection}/records?${params.toString()}`
);
return data.items ?? [];
const items: T[] = first.items ?? [];
const total = first.totalItems ?? 0;
// Fetch remaining pages if there are more records than the first page holds.
const totalPages = Math.ceil(total / perPage);
for (let page = 2; page <= totalPages; page++) {
params.set('page', String(page));
const data = await pbGet<PBList<T>>(
`/api/collections/${collection}/records?${params.toString()}`
);
items.push(...(data.items ?? []));
}
return items;
}
async function listN<T>(collection: string, n: number, filter = '', sort = ''): Promise<T[]> {