Fixed barcodes validation problem

This commit is contained in:
Alexander Cerutti
2019-03-30 17:35:12 +01:00
parent d9a3be0376
commit 33ca24d28d

View File

@@ -363,14 +363,23 @@ class Pass {
data = [data]; data = [data];
} }
// messageEncoding is required but has a default value. // Stripping from the array not-object elements, objects with no message
// Therefore I assign a validated version of the object with the default value // and the ones that does not pass validation.
// to the ones that doesn't have messageEncoding. // Validation assign default value to missing parameters (if any).
// if o is not a valid object, false is returned and then filtered later
let valid = data let valid = data.reduce((acc, current) => {
.map(o => schema.getValidated(o, "barcode")) if (!(current && current instanceof Object && current.hasOwnProperty("message"))) {
.filter(o => !!Object.keys(o).length); return acc;
}
let validated = schema.getValidated(current, "barcode");
if (!(validated && validated instanceof Object && Object.keys(validated).length)) {
return acc;
}
return [...acc, validated];
}, []);
if (valid.length) { if (valid.length) {
this._props["barcode"] = valid[0]; this._props["barcode"] = valid[0];