localhost_oa_based/src/helper/paginate/create-pagination.ts

27 lines
560 B
TypeScript
Raw Normal View History

2024-10-16 11:30:51 +08:00
import { IPaginationMeta } from './interface';
import { Pagination } from './pagination';
export function createPaginationObject<T>({
items,
totalItems,
currentPage,
limit
}: {
items: T[];
totalItems?: number;
currentPage: number;
limit: number;
}): Pagination<T> {
const totalPages = totalItems !== undefined ? Math.ceil(totalItems / limit) : undefined;
const meta: IPaginationMeta = {
totalItems,
itemCount: items.length,
itemsPerPage: limit,
totalPages,
currentPage
};
return new Pagination<T>(items, meta);
}