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.
20 lines
512 B
JavaScript
20 lines
512 B
JavaScript
"use strict";
|
|
|
|
function applyNormalizations(payload, normalizations) {
|
|
return normalizations.reduce((current, normalization) => {
|
|
let changes = normalization(current);
|
|
|
|
if (changes == null) {
|
|
return current;
|
|
} else {
|
|
return Object.assign(current, changes);
|
|
}
|
|
}, Object.assign({}, payload));
|
|
}
|
|
|
|
module.exports = function createNormalizationMiddleware(normalizations) {
|
|
return function normalizePayload(req, _res, next) {
|
|
req.body = applyNormalizations(req.body, normalizations);
|
|
next();
|
|
}
|
|
}; |