-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (25 loc) · 1.07 KB
/
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
26
27
let consts = require('./lib/consts.js');
let httpError = require('./lib/httpError.js');
let helper = require('./lib/helpers.js');
var hasReqParam = module.exports.hasReqParam = function (paramArray) {
return hasReqParam[paramArray] || (hasReqParam[paramArray] = function (req, res, next) {
var reqBody = req.body;
try {
var counter = paramArray.length;
let responseArray = [];
for (var i = 0; i < paramArray.length; i++) {
if (!reqBody.hasOwnProperty([paramArray[i]])) {
responseArray.push(consts.MISSING_PARAM(paramArray[i]));
}
counter--;
if (counter == 0 && responseArray.length > 0) {
helper.sendError(new httpError(consts.BAD_REQUEST, { response: responseArray }), req, res);
} else if (counter == 0) {
next();
}
}
} catch (e) {
helper.sendError(new httpError(consts.BAD_REQUEST, { response: consts.INVALID_BODY }), req, res);
}
})
};