refactor: made project service to use pagination

This commit is contained in:
2026-07-02 16:51:11 +03:30
parent 4b95d35d87
commit c22a41d29b
5 changed files with 109 additions and 35 deletions
+29
View File
@@ -0,0 +1,29 @@
import { IPageFormat } from "../interfaces/IPagination";
export function buildPageFormat(
page: number,
limit: number,
totalItems: number,
baseUrl: string,
): IPageFormat {
const totalPages = Math.ceil(totalItems / limit);
const prevPage =
page > 1
? `${baseUrl}?page=${page - 1}&limit=${limit}`
: false;
const nextPage =
page < totalPages
? `${baseUrl}?page=${page + 1}&limit=${limit}`
: false;
return {
page,
limit,
totalItems,
totalPages,
prevPage,
nextPage,
};
}
@@ -0,0 +1,6 @@
import { IPageFormat } from "./IPagination";
export interface PaginatedResult<T> {
data: T[];
meta: IPageFormat;
}