1 | module.exports = function normalizeQuery (params, paginate) {
|
2 | let query = Object.assign({}, params.query);
|
3 |
|
4 | if (paginate && paginate.default) {
|
5 | const lower = query.$limit ? Number(query.$limit) : paginate.default;
|
6 | const upper = typeof paginate.max === 'number' ? paginate.max : Number.MAX_VALUE;
|
7 |
|
8 | query.size = Math.min(lower, upper);
|
9 | delete query.$limit;
|
10 | }
|
11 |
|
12 | if (query.$limit) {
|
13 | query.size = query.$limit;
|
14 | delete query.$limit;
|
15 | }
|
16 |
|
17 | if (query.$skip) {
|
18 | query.offset = query.$skip;
|
19 | delete query.$skip;
|
20 | }
|
21 |
|
22 | return query;
|
23 | };
|