From 4546774916e3d563b6ebc301d00c5b7fb6d3262e Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sun, 30 Jun 2019 02:03:24 +0200 Subject: [PATCH] Improved how pass props are loaded from overrides and pass.json --- src/pass.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/pass.ts b/src/pass.ts index 6d8fc8d..c26ca8e 100644 --- a/src/pass.ts +++ b/src/pass.ts @@ -72,29 +72,25 @@ export class Pass implements PassIndexSignature { throw new Error(formatMessage("OVV_KEYS_BADFORMAT")) } - this._props = [ + this[passProps] = { + ...( + [ "barcodes", "barcode", "expirationDate", "voided", "beacons", "locations", "relevantDate", "nfc" - ].reduce((acc, current) => { - if (!this.passCore[current]) { - return acc; - } - - acc[current] = this.passCore[current]; - return acc; - }, {}); - - if (Object.keys(validOverrides).length) { - this._props = { ...this._props, ...validOverrides }; - } + ].reduce((acc, current) => + !this.passCore.hasOwnProperty(current) && acc || + ({ ...acc, [current]: this.passCore[current] || undefined }) + , {}) + ), + ...(validOverrides || {}) + }; this.type = Object.keys(this.passCore) .find(key => /(boardingPass|eventTicket|coupon|generic|storeCard)/.test(key)) as keyof schema.ValidPassType; if (!this.type) { - // @TODO: change error message to say it is invalid or missing throw new Error(formatMessage("NO_PASS_TYPE")); }