Skip to content

Commit

Permalink
Merge pull request #174 from saplingjs/feature/default-limit
Browse files Browse the repository at this point in the history
Implement default limit
  • Loading branch information
groenroos authored Apr 4, 2021
2 parents e8b0a1c + 832d525 commit f48a949
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = async function (next) {
secret: this.utils.randString(),
showError: true,
strict: false,
limit: 100,
production: 'auto',
db: {
driver: 'Memory'
Expand Down
11 changes: 11 additions & 0 deletions lib/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,24 @@ module.exports = class Storage {
/* Check if we're logged in */
this.app.user.isUserAuthenticatedForRoute(request, response);

/* Parse max limit */
const limit = (this.config.limit && this.config.limit > 0) ? this.config.limit : false;

/* Parse limit options */
if ('limit' in request.query) {
options.limit = Number(request.query.limit) || null;

/* If max limit is set in config, ensure we don't go over it */
if (limit && options.limit > limit) {
options.limit = limit;
}

if ('skip' in request.query) {
options.skip = Number(request.query.skip) || null;
}
} else if (limit) {
/* If max limit is set in config, enforce it */
options.limit = limit;
}

/* Parse sorting option */
Expand Down

0 comments on commit f48a949

Please sign in to comment.