refactor: changed functions to use pagination logic correctly
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user