Skip to content

Commit

Permalink
fix(options): add warning if provide limit or offset
Browse files Browse the repository at this point in the history
fix #1
  • Loading branch information
lgaticaq committed Sep 14, 2018
1 parent 3c0abc7 commit 206a8ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const options = {
const { docs, pages, total } = await db.MyModel.paginate(options)
```

**NOTE:** _If **options** include **limit** or **offset** are ignored._

## License

[MIT](https://tldrlegal.com/license/mit-license)
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class SequelizePaginate {
const pages = Math.ceil(total / params.paginate)
options.limit = params.paginate
options.offset = params.paginate * (params.page - 1)
/* eslint-disable no-console */
if (params.limit) {
console.warn(`(sequelize-pagination) Warning: limit option is ignored.`)
}
if (params.offset) {
console.warn(`(sequelize-pagination) Warning: offset option is ignored.`)
}
/* eslint-enable no-console */
if (params.order) options.order = params.order
const docs = await Model.findAll(options)
return { docs, pages, total }
Expand Down

0 comments on commit 206a8ae

Please sign in to comment.