validateQuery function
Validates the data in req.queryParameters
, and sets the query to
filtered data before continuing the response.
Implementation
RequestHandler validateQuery(Validator validator,
{String errorMessage = 'Invalid data.'}) {
return (RequestContext req, res) async {
var app = req.app;
if (app != null) {
var result =
await asyncApplyValidator(validator, req.queryParameters, app);
if (result.errors.isNotEmpty) {
throw AngelHttpException.badRequest(
message: errorMessage, errors: result.errors);
}
req.queryParameters
..clear()
..addAll(result.data);
}
return true;
};
}