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