paginated_result.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.PaginatedResult = void 0;
  4. class PaginatedResult {
  5. totalResults;
  6. totalPages;
  7. resultsPerPage;
  8. currentPage;
  9. items;
  10. constructor(items, headers) {
  11. this.totalResults = parseInt(headers["x-pagination-total-count"]);
  12. this.totalPages = parseInt(headers["x-pagination-page-count"]);
  13. this.resultsPerPage = parseInt(headers["x-pagination-limit"]);
  14. this.currentPage = parseInt(headers["x-pagination-page"]);
  15. this.items = items;
  16. return this;
  17. }
  18. hasNextPage() {
  19. return this.currentPage > 0 && this.currentPage < this.totalPages;
  20. }
  21. hasPrevPage() {
  22. return this.currentPage > 1;
  23. }
  24. isLastPage() {
  25. return !this.hasNextPage();
  26. }
  27. isFirstPage() {
  28. return !this.hasPrevPage();
  29. }
  30. nextPage() {
  31. if (this.isLastPage()) {
  32. return this.currentPage;
  33. }
  34. else {
  35. return this.currentPage + 1;
  36. }
  37. }
  38. prevPage() {
  39. if (this.isFirstPage()) {
  40. return this.currentPage;
  41. }
  42. else {
  43. return this.currentPage - 1;
  44. }
  45. }
  46. }
  47. exports.PaginatedResult = PaginatedResult;
  48. //# sourceMappingURL=paginated_result.js.map