aravindnc/mongoose-paginate-v2

PaginateResult

mat-twg opened this issue · 0 comments

Wrong PaginateResult interface or implementation

  interface PaginateResult<T> {
    docs: T[];
    totalDocs: number;
    limit: number;
    hasPrevPage: boolean;
    hasNextPage: boolean;
    page?: number | undefined;
    totalPages: number;
    offset: number;
    prevPage?: number | null | undefined;
    nextPage?: number | null | undefined;
    pagingCounter: number;
    meta?: any;
    [customLabel: string]: T[] | number | boolean | null | undefined;
  }

based on this, it is expected that the offset field is required instead of the page field, as I can judge from the results

// base result out
{
  "docs": [],
  "totalDocs": 0,
  "limit": 10,
  "totalPages": 1,
  "page": 1,
  "pagingCounter": 1,
  "hasPrevPage": false,
  "hasNextPage": false,
  "prevPage": null,
  "nextPage": null
}

you should think about swapping offset and page places, so use interfaces in tests...

  interface PaginateResult<T> {
    page: number | undefined;
    offset?: number;
  }