mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
Changed validation method in barcode; added function 'getValidated' to obtain validation content
This commit is contained in:
17
index.js
17
index.js
@@ -317,12 +317,21 @@ class Pass {
|
|||||||
data = [data];
|
data = [data];
|
||||||
}
|
}
|
||||||
|
|
||||||
let valid = data.filter(b => b instanceof Object && schema.isValid(b, "barcode"));
|
// 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
|
||||||
|
|
||||||
this.props["barcode"] = valid[0] || undefined;
|
let valid = data
|
||||||
this.props["barcodes"] = valid || [];
|
.map(o => schema.getValidated(o, "barcode"))
|
||||||
|
.filter(o => o instanceof Object);
|
||||||
|
|
||||||
// I bind "this" to get a clean this when returning from the methods
|
if (valid.length) {
|
||||||
|
this.props["barcode"] = valid[0];
|
||||||
|
this.props["barcodes"] = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// I bind "this" to get a clean context (without these two methods) when returning from the methods
|
||||||
|
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
length: valid.length,
|
length: valid.length,
|
||||||
|
|||||||
18
schema.js
18
schema.js
@@ -32,7 +32,7 @@ let supportedOptions = Joi.object().keys({
|
|||||||
|
|
||||||
let barcode = Joi.object().keys({
|
let barcode = Joi.object().keys({
|
||||||
altText: Joi.string(),
|
altText: Joi.string(),
|
||||||
messageEncoding: Joi.string().default("iso-8859-1").required(),
|
messageEncoding: Joi.string().default("iso-8859-1"),
|
||||||
format: Joi.string().required().regex(/(PKBarcodeFormatQR|PKBarcodeFormatPDF417|PKBarcodeFormatAztec|PKBarcodeFormatCode128)/, "barcodeType"),
|
format: Joi.string().required().regex(/(PKBarcodeFormatQR|PKBarcodeFormatPDF417|PKBarcodeFormatAztec|PKBarcodeFormatCode128)/, "barcodeType"),
|
||||||
message: Joi.string().required()
|
message: Joi.string().required()
|
||||||
});
|
});
|
||||||
@@ -140,9 +140,21 @@ let filter = (opts, schemaName) => {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, isObject ? {} : []);
|
}, isObject ? {} : []);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let getValidated = (opts, schemaName) => {
|
||||||
|
let resolvedSchema = resolveSchemaName(schemaName);
|
||||||
|
let validation = Joi.validate(opts, resolvedSchema);
|
||||||
|
|
||||||
|
if (validation.error) {
|
||||||
|
return !validation.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return validation.value;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isValid,
|
isValid,
|
||||||
filter
|
filter,
|
||||||
|
getValidated
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user