1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 22:19:26 +00:00

Validator should add non-validated fields to the returned map too

This commit is contained in:
2022-02-14 21:29:01 +00:00
parent f62187bf60
commit 6cd2d9db4a

View File

@@ -40,7 +40,8 @@ function passwordsMatch(password1, password2) {
* @return {Object} results
* @return {Map<string, string>} results.fields - Sanitised and validated fields
*/
function validate(body, fields, validation = {}) {
function validate(originalBody, fields, validation = {}) {
const body = { ...originalBody };
const fieldsMap = new Map();
// Check all required fields are not empty, and sanitise them
@@ -51,8 +52,13 @@ function validate(body, fields, validation = {}) {
throw new Error(`${field} is missing`);
fieldsMap.set(field, cleanField);
delete body[field];
}
for (const [ field, content ] of Object.entries(body))
fieldsMap.set(field, content);
// Handle validation as required in options
for (const [ check, checkOpts ] of Object.entries(validation)) {
let valid;