-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (32 loc) · 1.15 KB
/
index.js
File metadata and controls
42 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const builder = require('./builder');
const utils = require('./utils');
function build(options = {}) {
return (req, res, next) => {
try {
// parse & validate the query object for numbers & boolean values
req.query = utils.parseQuery(req.query);
req.query = utils.validator(req.query);
// parse & validate the default options
options = utils.parseQuery(options);
options = utils.validator(options);
// check use default flag in the query to use default options for the builder
builder.defaults = req.query.dontUseDefault ? {} : options;
// build the select fields for the request
builder.select(req.query)
// build the filter fields for the request
.filter(req.query)
// build the select fields for the request
.with(req.query)
// build the select fields for the request
.deep(req.query)
// build the filter fields for the request
.limit(req.query)
// build the select fields for the request
.sort(req.query);
return next();
} catch (error) {
return next(error);
}
};
}
module.exports.build = build;