fix: logic in checkRequired

if req.body was undefined req.query wasn't checked
This commit is contained in:
Barış Soner Uşaklı
2026-03-03 11:33:52 -05:00
parent b268164686
commit 2428602f27

View File

@@ -308,14 +308,20 @@ middleware.validateAuth = helpers.try(async (req, res, next) => {
}); });
middleware.checkRequired = function (fields, req, res, next) { middleware.checkRequired = function (fields, req, res, next) {
const body = req.body || {};
const query = req.query || {};
// Used in API calls to ensure that necessary parameters/data values are present // Used in API calls to ensure that necessary parameters/data values are present
const missing = fields.filter( const missing = fields.filter(
field => req.body && !req.body.hasOwnProperty(field) && !req.query.hasOwnProperty(field) field => !body.hasOwnProperty(field) && !query.hasOwnProperty(field)
); );
if (!missing.length) { if (!missing.length) {
return next(); return next();
} }
controllers.helpers.formatApiResponse(400, res, new Error(`[[error:required-parameters-missing, ${missing.join(' ')}]]`)); controllers.helpers.formatApiResponse(
400,
res,
new Error(`[[error:required-parameters-missing, ${missing.join(' ')}]]`)
);
}; };