express-params-checker
Advanced tools
Comparing version 1.0.0 to 1.0.1
27
index.js
const _ = require('lodash') | ||
exports.has = (...requiredFields) => { | ||
function check(para, requiredFields) { | ||
const checkFunc = (req) => { | ||
let params = _.extend({}, req.query, req.body, req.params) | ||
for(let i = 0; i < requiredFields.length; i++){ | ||
if(!_.has(params, requiredFields[i])){ | ||
if(!_.has(para, requiredFields[i])){ | ||
let err = new Error(`Missing parameter: ${requiredFields[i]}`) | ||
@@ -13,3 +12,3 @@ err.status = 400 | ||
} | ||
req.params = params | ||
req.para = para | ||
} | ||
@@ -22,1 +21,21 @@ | ||
} | ||
exports.has = (...requiredFields) => { | ||
let para = _.extend({}, req.query, req.body, req.params) | ||
check(para, requiredFields) | ||
} | ||
exports.QueryHas = (...requiredFields) => { | ||
let para = req.query | ||
check(para, requiredFields) | ||
} | ||
exports.BodyHas = (...requiredFields) => { | ||
let para = req.body | ||
check(para, requiredFields) | ||
} | ||
exports.ParamHas = (...requiredFields) => { | ||
let para = req.params | ||
check(para, requiredFields) | ||
} |
{ | ||
"name": "express-params-checker", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1177
33