aravindnc / mongoose-paginate-v2

A custom pagination library for Mongoose with customizable labels.

Home Page:https://www.npmjs.com/package/mongoose-paginate-v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

customLabels: typescript

torquan opened this issue · comments

Hi,

is it possible to customize the PaginateModel to use my custom labels?

The Readme helped me with the paginationResult, but I'm stuck with those labels.

Hi @torquan

you can achive this be override the interface of the results by creating mongoose/index.d.ts in your types folder if you don't have one and add the code below into the file

declare module 'mongoose' {
  interface PaginateResult<T> {
    docs: T[]
    data: 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
   
   // You can add your customLabels here, for example:
    perPage: number
  }
}

also you can remove the whole keys above and replace them with your custom labels if you have set your custom labels in plugin global options

Hope this help