|
| 1 | +import { parseObject } from "../../common/utils.mjs"; |
| 2 | +import walletap from "../../walletap.app.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "walletap-update-pass", |
| 6 | + name: "Update Pass", |
| 7 | + description: "Updates an existing Walletap pass and pushes the updated pass to the user. [See the documentation](https://walletap.io/docs/api#tag/Pass/operation/updatePass)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + annotations: { |
| 11 | + destructiveHint: false, |
| 12 | + openWorldHint: true, |
| 13 | + readOnlyHint: false, |
| 14 | + }, |
| 15 | + props: { |
| 16 | + walletap, |
| 17 | + passId: { |
| 18 | + type: "string", |
| 19 | + label: "Pass ID", |
| 20 | + description: "Walletap generated pass ID", |
| 21 | + }, |
| 22 | + templateFields: { |
| 23 | + type: "object", |
| 24 | + label: "Template Fields", |
| 25 | + description: "The template fields to update. Generic (object) or Loyalty (object) or Gift Card (object) or Event Ticket (object) or Offer/Coupon (object)", |
| 26 | + optional: true, |
| 27 | + }, |
| 28 | + memberId: { |
| 29 | + type: "string", |
| 30 | + label: "Member ID", |
| 31 | + description: "The ID connecting this pass to a member in your system", |
| 32 | + optional: true, |
| 33 | + }, |
| 34 | + customFields: { |
| 35 | + type: "object", |
| 36 | + label: "Custom Fields", |
| 37 | + description: "Custom fields defined in pass design, using field IDs as object keys", |
| 38 | + optional: true, |
| 39 | + }, |
| 40 | + redemptionValue: { |
| 41 | + type: "string", |
| 42 | + label: "Redemption Value", |
| 43 | + description: "Value to be encoded in barcode and/or NFC payload. If not provided, it is set to `externalId`. If also not provided, it is set to Walletap generated `id`", |
| 44 | + optional: true, |
| 45 | + }, |
| 46 | + isValid: { |
| 47 | + type: "boolean", |
| 48 | + label: "Valid", |
| 49 | + description: "If set to `false` it invalidates the pass and moves it to the \"Expired passes\" section in user Wallet", |
| 50 | + optional: true, |
| 51 | + }, |
| 52 | + email: { |
| 53 | + type: "string", |
| 54 | + label: "Email", |
| 55 | + description: "The email of the user", |
| 56 | + optional: true, |
| 57 | + }, |
| 58 | + phone: { |
| 59 | + type: "string", |
| 60 | + label: "Phone", |
| 61 | + description: "The phone of the user", |
| 62 | + optional: true, |
| 63 | + }, |
| 64 | + }, |
| 65 | + async run({ $ }) { |
| 66 | + const response = await this.walletap.updatePass({ |
| 67 | + $, |
| 68 | + data: { |
| 69 | + id: this.passId, |
| 70 | + templateFields: parseObject(this.templateFields), |
| 71 | + memberId: this.memberId, |
| 72 | + customFields: parseObject(this.customFields), |
| 73 | + redemptionValue: this.redemptionValue, |
| 74 | + isValid: this.isValid, |
| 75 | + email: this.email, |
| 76 | + phone: this.phone, |
| 77 | + }, |
| 78 | + }); |
| 79 | + |
| 80 | + $.export("$summary", `Successfully updated pass with id: ${response.id}`); |
| 81 | + return response; |
| 82 | + }, |
| 83 | +}; |
0 commit comments