Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit af15ea6

Browse files
#35 - Support pagination
1 parent 55fe59d commit af15ea6

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Configuration for the application is at config/default.js and config/production.
1616
- AUTH_SECRET: TC Authentication secret
1717
- VALID_ISSUERS: valid issuers for TC authentication
1818
- PAGE_SIZE: the default pagination limit
19+
- MAX_PAGE_SIZE: the maximum pagination size
1920
- API_VERSION: the API version
2021
- AWS_ACCESS_KEY_ID: The AWS access key
2122
- AWS_SECRET_ACCESS_KEY: The AWS secret key

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
: '["https://topcoder-dev.auth0.com/", "https://api.topcoder.com"]',
1212

1313
PAGE_SIZE: process.env.PAGE_SIZE || 20,
14+
MAX_PAGE_SIZE: parseInt(process.env.MAX_PAGE_SIZE) || 100,
1415
API_VERSION: process.env.API_VERSION || 'api/1.0',
1516

1617
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,

src/bootstrap.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
* add logger and joi to services
33
*/
44

5+
const config = require('config')
56
const fs = require('fs')
67
const path = require('path')
78
const logger = require('./common/logger')
9+
const joi = require('joi')
10+
11+
joi.id = () => joi.number().integer().min(1)
12+
joi.pageSize = () => joi.number().integer().min(1).max(config.get('MAX_PAGE_SIZE'))
813

914
/**
1015
* add logger and joi schema to service

src/common/service-helper.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ function getServiceMethods (Model, createSchema, patchSchema, searchSchema, buil
285285
}
286286

287287
search.schema = {
288-
query: searchSchema,
288+
query: {
289+
page: joi.id(),
290+
perPage: joi.pageSize(),
291+
...searchSchema
292+
},
289293
auth: joi.object()
290294
}
291295

0 commit comments

Comments
 (0)