import { PaginatedResult as PaginatedResultInterface } from "../interfaces/paginated_result" ; export class PaginatedResult implements PaginatedResultInterface { totalResults : number ; totalPages : number ; resultsPerPage : number ; currentPage : number ; items : any [ ] ; constructor ( items , headers ) { this . totalResults = parseInt ( Object ( headers ) [ "x-pagination-total-count" ] ) ; this . totalPages = parseInt ( Object ( headers ) [ "x-pagination-page-count" ] ) ; this . resultsPerPage = parseInt ( Object ( headers ) [ "x-pagination-limit" ] ) ; this . currentPage = parseInt ( Object ( headers ) [ "x-pagination-page" ] ) ; this . items = items ; return this ; } hasNextPage ( ) { return this . currentPage > 0 && this . currentPage < this . totalPages ; } hasPrevPage ( ) { return this . currentPage > 1 ; } isLastPage ( ) { return ! this . hasNextPage ( ) ; } isFirstPage ( ) { return ! this . hasPrevPage ( ) ; } nextPage ( ) { if ( this . isLastPage ( ) ) { return this . currentPage ; } else { return this . currentPage + 1 ; } } prevPage ( ) { if ( this . isFirstPage ( ) ) { return this . currentPage ; } else { return this . currentPage - 1 ; } } }