import { BadRequestException } from "./http-exception.helper" export interface IPaginateListPayload { list: Array count: number page: number pageSize: number } export interface IPaginateListResponse { list: Array pagination: { total: number currentPage: number totalPages: number } } export interface IPaginateFilters { page?: number; pageSize?: number; } export class PaginationHelper { static build({ list, count, page, pageSize }: IPaginateListPayload): IPaginateListResponse { const totalPages = Math.ceil(count / pageSize); const currentPage = Math.min(page, totalPages); return { list, pagination: { total: count, currentPage, totalPages, }, } } static resolve({ page, pageSize }: IPaginateFilters){ if(page! < 1 || pageSize! < 1) throw new BadRequestException('The page must be greater than 1') } }