Add pagination to ISAC registries

This commit is contained in:
JB
2026-07-25 01:03:56 -04:00
parent e528f18d8f
commit c286d1783d
16 changed files with 192 additions and 31 deletions
+18
View File
@@ -0,0 +1,18 @@
import type { URL } from 'node:url';
export const PAGE_SIZE_PRESETS = [10, 25, 50, 100] as const;
export function getPagination(url: URL, total: number) {
const requestedSize = Number(url.searchParams.get('perPage'));
const perPage = PAGE_SIZE_PRESETS.includes(requestedSize as (typeof PAGE_SIZE_PRESETS)[number]) ? requestedSize : 25;
const pageCount = Math.max(1, Math.ceil(total / perPage));
const requestedPage = Number(url.searchParams.get('page'));
const page = Math.min(pageCount, Math.max(1, Number.isInteger(requestedPage) ? requestedPage : 1));
return {
page,
perPage,
total,
pageCount,
offset: (page - 1) * perPage
};
}