Added relevace() method to set beacons and locations; Added schemas for beaconsDict and locationsDict

This commit is contained in:
alexandercerutti
2018-08-20 16:40:04 +02:00
parent 8cda71309d
commit 8634d540b8
3 changed files with 58 additions and 2 deletions

View File

@@ -194,6 +194,39 @@ class Pass {
return this;
}
relevance(type, data) {
let types = ["beacons", "locations", "maxDistance", "relevantDate"];
if (!type || !data || !types.includes(type)) {
return 0;
}
if (type === "beacons" || type === "locations") {
if (!(data instanceof Array)) {
data = [data];
}
let valid = data.filter(d => schema.isValid(d, schema.constants[type+"Dict"]));
this.props[type] = valid;
return valid.length;
}
if (type === "maxDistance" && (typeof data === "string" || typeof data === "number")) {
this.props[type] = String(data);
return 1;
} else if (type === "relevantDate") {
let convDate = dateToW3CString(data);
if (convDate) {
this.props[type] = convDate;
}
return Number(!!convDate);
}
}
/**
* Checks if pass model type is one of the supported ones
*

View File

@@ -30,6 +30,20 @@ let field = Joi.object().keys({
value: Joi.string().required()
});
let beaconsDict = Joi.object().keys({
major: Joi.number().integer().positive().max(65536),
minor: Joi.number().integer().positive().max(65536),
proximityUUID: Joi.string().required(),
relevantText: Joi.string()
});
let locationsDict = Joi.object().keys({
altitude: Joi.number(),
latitude: Joi.number().required(),
longitude: Joi.number().required(),
relevantText: Joi.string()
});
let struct = {
auxiliaryFields: Joi.array().items(field),
backFields: Joi.array().items(field),
@@ -49,7 +63,9 @@ module.exports = {
barcode,
field,
basicStructure,
boardingStructure
boardingStructure,
beaconsDict,
locationsDict
},
isValid: (opts, schemaName, debug = false) => {
let validation = Joi.validate(opts, schemaName);

View File

@@ -64,12 +64,19 @@ function manageRequest(request, response) {
"LOCATION": "Location"
});
// non-existing language code
// non-existing language code get also inserted but (probabily) not used
pass.localize("ol", {
"EVENT": "numashat",
"LOCATION": "abelret"
});
pass.relevance("locations", [{
latitude: 45.601565099999995,
longitude: 12.320653600000002
}]);
pass.relevance("maxDistance", 150);
//pass.localize("zu", {});
pass.primaryFields.push({