Moved pass types into _validateType

This commit is contained in:
alexandercerutti
2018-08-05 18:32:02 +02:00
parent 565916c65d
commit 7efbb9c3d1

View File

@@ -6,10 +6,14 @@ const async = require("async");
const stream = require("stream");
const schema = require("./schema.js");
const util = require("util");
const readdir = util.promisify(fs.readdir);
const readFile = util.promisify(fs.readFile);
class Pass {
constructor(options) {
this.options = options;
this.passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
this.overrides = this.options.overrides || {};
this.Certificates = {};
this.model = "";
@@ -205,15 +209,17 @@ class Pass {
*/
_validateType(passBuffer) {
let passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
try {
let passFile = JSON.parse(passBuffer.toString("utf8"));
let index = this.passTypes.findIndex(passType => passFile.hasOwnProperty(passType));
let index = passTypes.findIndex(passType => passFile.hasOwnProperty(passType));
if (index == -1) {
return false;
}
let type = this.passTypes[index];
let type = passTypes[index];
return schema.isValid(passFile[type], schema.constants[(type === "boardingPass" ? "boarding" : "basic") + "Structure"]);
} catch (e) {
return false;