refactor: changed functions to use pagination logic correctly

This commit is contained in:
2026-07-05 19:20:08 +03:30
parent a14bd490be
commit 9f61152d94
5 changed files with 63 additions and 69 deletions
-29
View File
@@ -1,29 +0,0 @@
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,
};
}