-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
25 lines (20 loc) · 818 Bytes
/
index.js
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
exports = module.exports = function(options) {
options = options || {}
return function requireKeys(request, response, next) {
for ( var name in options ) {
// name as in 'body'
var required_keys = options[name]
required_keys = Array.isArray(required_keys) ? required_keys : [required_keys]
for ( var index in required_keys ) {
// key as in 'data', or 'language'
var key = required_keys[index]
if ( !request[name] || !request[name].hasOwnProperty(key) ) {
var error_message = 'Error: request missing ' + key + ' in ' + name
response.statusCode = 400
return next(error_message)
}
}
}
next()
}
}