mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Improved how pass props are loaded from overrides and pass.json
This commit is contained in:
24
src/pass.ts
24
src/pass.ts
@@ -72,29 +72,25 @@ export class Pass implements PassIndexSignature {
|
|||||||
throw new Error(formatMessage("OVV_KEYS_BADFORMAT"))
|
throw new Error(formatMessage("OVV_KEYS_BADFORMAT"))
|
||||||
}
|
}
|
||||||
|
|
||||||
this._props = [
|
this[passProps] = {
|
||||||
|
...(
|
||||||
|
[
|
||||||
"barcodes", "barcode",
|
"barcodes", "barcode",
|
||||||
"expirationDate", "voided",
|
"expirationDate", "voided",
|
||||||
"beacons", "locations",
|
"beacons", "locations",
|
||||||
"relevantDate", "nfc"
|
"relevantDate", "nfc"
|
||||||
].reduce<schema.ValidPass>((acc, current) => {
|
].reduce<schema.ValidPass>((acc, current) =>
|
||||||
if (!this.passCore[current]) {
|
!this.passCore.hasOwnProperty(current) && acc ||
|
||||||
return acc;
|
({ ...acc, [current]: this.passCore[current] || undefined })
|
||||||
}
|
, {})
|
||||||
|
),
|
||||||
acc[current] = this.passCore[current];
|
...(validOverrides || {})
|
||||||
return acc;
|
};
|
||||||
}, {});
|
|
||||||
|
|
||||||
if (Object.keys(validOverrides).length) {
|
|
||||||
this._props = { ...this._props, ...validOverrides };
|
|
||||||
}
|
|
||||||
|
|
||||||
this.type = Object.keys(this.passCore)
|
this.type = Object.keys(this.passCore)
|
||||||
.find(key => /(boardingPass|eventTicket|coupon|generic|storeCard)/.test(key)) as keyof schema.ValidPassType;
|
.find(key => /(boardingPass|eventTicket|coupon|generic|storeCard)/.test(key)) as keyof schema.ValidPassType;
|
||||||
|
|
||||||
if (!this.type) {
|
if (!this.type) {
|
||||||
// @TODO: change error message to say it is invalid or missing
|
|
||||||
throw new Error(formatMessage("NO_PASS_TYPE"));
|
throw new Error(formatMessage("NO_PASS_TYPE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user