You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
392 B
JavaScript
18 lines
392 B
JavaScript
4 years ago
|
"use strict";
|
||
|
|
||
|
const aggregrateErrors = require("../aggregrate-errors");
|
||
|
|
||
|
module.exports = function createValidationMethod(validationFunction) {
|
||
|
return function (... args) {
|
||
|
let { errors, newValue } = validationFunction(... args);
|
||
|
|
||
|
let aggregratedError = aggregrateErrors(errors);
|
||
|
|
||
|
if (aggregratedError != null) {
|
||
|
throw aggregratedError;
|
||
|
} else {
|
||
|
return newValue;
|
||
|
}
|
||
|
};
|
||
|
};
|