mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Added relevace() method to set beacons and locations; Added schemas for beaconsDict and locationsDict
This commit is contained in:
33
index.js
33
index.js
@@ -194,6 +194,39 @@ class Pass {
|
|||||||
return this;
|
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
|
* Checks if pass model type is one of the supported ones
|
||||||
*
|
*
|
||||||
|
|||||||
18
schema.js
18
schema.js
@@ -30,6 +30,20 @@ let field = Joi.object().keys({
|
|||||||
value: Joi.string().required()
|
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 = {
|
let struct = {
|
||||||
auxiliaryFields: Joi.array().items(field),
|
auxiliaryFields: Joi.array().items(field),
|
||||||
backFields: Joi.array().items(field),
|
backFields: Joi.array().items(field),
|
||||||
@@ -49,7 +63,9 @@ module.exports = {
|
|||||||
barcode,
|
barcode,
|
||||||
field,
|
field,
|
||||||
basicStructure,
|
basicStructure,
|
||||||
boardingStructure
|
boardingStructure,
|
||||||
|
beaconsDict,
|
||||||
|
locationsDict
|
||||||
},
|
},
|
||||||
isValid: (opts, schemaName, debug = false) => {
|
isValid: (opts, schemaName, debug = false) => {
|
||||||
let validation = Joi.validate(opts, schemaName);
|
let validation = Joi.validate(opts, schemaName);
|
||||||
|
|||||||
@@ -64,12 +64,19 @@ function manageRequest(request, response) {
|
|||||||
"LOCATION": "Location"
|
"LOCATION": "Location"
|
||||||
});
|
});
|
||||||
|
|
||||||
// non-existing language code
|
// non-existing language code get also inserted but (probabily) not used
|
||||||
pass.localize("ol", {
|
pass.localize("ol", {
|
||||||
"EVENT": "numashat",
|
"EVENT": "numashat",
|
||||||
"LOCATION": "abelret"
|
"LOCATION": "abelret"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pass.relevance("locations", [{
|
||||||
|
latitude: 45.601565099999995,
|
||||||
|
longitude: 12.320653600000002
|
||||||
|
}]);
|
||||||
|
|
||||||
|
pass.relevance("maxDistance", 150);
|
||||||
|
|
||||||
//pass.localize("zu", {});
|
//pass.localize("zu", {});
|
||||||
|
|
||||||
pass.primaryFields.push({
|
pass.primaryFields.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user