mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Added StringField class for transitType field;
Added parsing specific for transit inside _patch method that throws Renamed fields.area in fieldsName
This commit is contained in:
18
fields.js
18
fields.js
@@ -5,7 +5,7 @@ const schema = require("./schema");
|
|||||||
* @see https://apple.co/2wkUBd
|
* @see https://apple.co/2wkUBd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FieldsArea {
|
class FieldsContainer {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.fields = [];
|
this.fields = [];
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,21 @@ class FieldsArea {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StringField {
|
||||||
|
set transitType(v) {
|
||||||
|
if (schema.isValid(v, schema.constants.transitType, true)) {
|
||||||
|
this.fields = v;
|
||||||
|
} else {
|
||||||
|
this.fields = this.fields && this.fields !== "" ? this.fields : "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get transitType() {
|
||||||
|
return this.fields;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
areas: ["primaryFields", "secondaryFields", "auxiliaryFields", "backFields", "headerFields"],
|
areas: ["primaryFields", "secondaryFields", "auxiliaryFields", "backFields", "headerFields"],
|
||||||
FieldsArea
|
FieldsContainer,
|
||||||
|
StringField
|
||||||
};
|
};
|
||||||
|
|||||||
13
index.js
13
index.js
@@ -6,7 +6,7 @@ const forge = require("node-forge");
|
|||||||
const archiver = require("archiver");
|
const archiver = require("archiver");
|
||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
const schema = require("./schema");
|
const schema = require("./schema");
|
||||||
const fields = require("./fields");
|
const { areas: fieldsName, FieldsContainer, StringField } = require("./fields");
|
||||||
const { errors, warnings } = require("./messages");
|
const { errors, warnings } = require("./messages");
|
||||||
|
|
||||||
const readdir = util.promisify(fs.readdir);
|
const readdir = util.promisify(fs.readdir);
|
||||||
@@ -21,7 +21,8 @@ class Pass {
|
|||||||
this.props = {};
|
this.props = {};
|
||||||
this.shouldOverwrite = !(this.options.hasOwnProperty("shouldOverwrite") && !this.options.shouldOverwrite);
|
this.shouldOverwrite = !(this.options.hasOwnProperty("shouldOverwrite") && !this.options.shouldOverwrite);
|
||||||
|
|
||||||
fields.areas.forEach(a => this[a] = new fields.FieldsArea());
|
fieldsName.forEach(a => this[a] = new FieldsContainer());
|
||||||
|
this.transitType = new StringField();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -523,12 +524,18 @@ class Pass {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fields.areas.forEach(area => {
|
fieldsName.forEach(area => {
|
||||||
if (this[area].fields.length) {
|
if (this[area].fields.length) {
|
||||||
passFile[this.type][area].push(...this[area].fields);
|
passFile[this.type][area].push(...this[area].fields);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.type === "boardingPass" && this.transitType) {
|
||||||
|
passFile[this.type]["transitType"] = this.transitType;
|
||||||
|
} else {
|
||||||
|
throw new Error("Cannot proceed with pass creation. transitType field is required for boardingPasses.");
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve(Buffer.from(JSON.stringify(passFile)));
|
return Promise.resolve(Buffer.from(JSON.stringify(passFile)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ module.exports = {
|
|||||||
basicStructure,
|
basicStructure,
|
||||||
boardingStructure,
|
boardingStructure,
|
||||||
beaconsDict,
|
beaconsDict,
|
||||||
locationsDict
|
locationsDict,
|
||||||
|
transitType
|
||||||
},
|
},
|
||||||
isValid: (opts, schemaName, debug = false) => {
|
isValid: (opts, schemaName, debug = false) => {
|
||||||
let validation = Joi.validate(opts, schemaName);
|
let validation = Joi.validate(opts, schemaName);
|
||||||
|
|||||||
Reference in New Issue
Block a user