Skip to content

Commit

Permalink
Adds improvements to the pagination "processQuery" function
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasrafael committed Jun 1, 2020
1 parent e635f28 commit ecd20ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/mapper/pagination.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
function pagination(query, options) {
const result = {}

result.limit = options.default.pagination.limit

if (query.limit) {
result.limit = processQuery(query.limit)
result.limit = processQuery(query.limit) || options.default.pagination.limit
}

if (options.use_page) {
result.page = options.default.pagination.page
if (query.page) {
result.page = processQuery(query.page)
result.page = processQuery(query.page) || options.default.pagination.page
}
} else {
result.skip = options.default.pagination.skip
if (query.skip) {
result.skip = processQuery(query.skip)
result.skip = processQuery(query.skip) || options.default.pagination.skip
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/index.custom.config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('queryFilter()', function () {
})
})

context('when use pagination with page and query page is not a number', function () {
context('when use pagination with page and query page and limit is not a number', function () {
it('should return pagination param with default limit', function () {

const expect_pagination = {
Expand All @@ -94,7 +94,7 @@ describe('queryFilter()', function () {
const options = JSON.parse(JSON.stringify(custom_options))
options.default.pagination = expect_pagination

const query = '?limit=teen'
const query = '?page=current&limit=teen'

return request(app)
.get(query)
Expand Down

0 comments on commit ecd20ec

Please sign in to comment.