Documented _validateType and changed its implementation

This commit is contained in:
alexandercerutti
2018-07-20 16:09:38 +02:00
parent ee5e1801f0
commit da1db13b52

View File

@@ -25,7 +25,7 @@ class Pass {
this.modelDirectory = null; this.modelDirectory = null;
this._parseSettings(options) this._parseSettings(options)
;// .then(() => console.log("WAT IS", this)); ;// .then(() => console.log("WAT IS", this));
this.passTypes = /^(boardingPass|eventTicket|coupon|generic|storeCard)$/; this.passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
} }
/** /**
@@ -214,11 +214,19 @@ class Pass {
}); });
} }
/**
Checks if pass model type is one of the supported ones
@method _validateType
@params {Buffer} passBuffer - buffer of the pass structure content
@returns {Boolean} - true if type is supported, false otherwise.
*/
_validateType(passBuffer) { _validateType(passBuffer) {
try { try {
let passFile = JSON.parse(passBuffer.toString("utf8")); let passFile = JSON.parse(passBuffer.toString("utf8"));
return Object.keys(passFile).some(key => this.passTypes.test(key)); return this.passTypes.some(passType => passFile.hasOwnProperty(passType));
} catch (e) { } catch (e) {
return false; return false;
} }
@@ -305,9 +313,7 @@ class Pass {
try { try {
let passFile = JSON.parse(passBuffer.toString("utf8")); let passFile = JSON.parse(passBuffer.toString("utf8"));
for (let prop in options) { Object.keys(options).forEach(opt => passFile[opt] = options[opt]);
passFile[prop] = options[prop];
}
return done(Buffer.from(JSON.stringify(passFile))); return done(Buffer.from(JSON.stringify(passFile)));
} catch(e) { } catch(e) {