UNPKG

@eagleeye-solutions/integration-events-common

Version:
61 lines 2.99 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPosConnectWalletSettleEventData = getPosConnectWalletSettleEventData; const atomic_operations_1 = require("./atomic-operations"); const atomic_operations_2 = require("./atomic-operations"); const atomic_operations_3 = __importDefault(require("./atomic-operations")); const wallet_account_transaction_entity_1 = require("./atomic-operations/wallet-account-transaction-entity"); /** * Returns an array of events derived from a POSCONNECT.WALLET.SETTLE event. * * @param event * @param configuration * @returns */ function getPosConnectWalletSettleEventData(event, opts) { let transactionAttributes = null; let pointsAttributes = null; let tierAttributes = null; const redeemedCoupons = []; for (const op of event.atomicOperations) { if ((0, atomic_operations_2.isWalletAccountTransactionEntityUpdatePoints)(op)) { // Always take the latest POINTS balance observed in the operations list try { pointsAttributes = (0, wallet_account_transaction_entity_1.getPointsAttributesFromWalletAccountTransactionEntity)(op); } catch { // Ignore if balance not available on this op. // By taking the latest POINTS balance observed in the operations list, // we ensure that we always have the most up-to-date balance regardless // of the its type. } } else if ((0, atomic_operations_1.isTierMembershipEntity)(op)) { tierAttributes = atomic_operations_3.default.TierMembershipEntity.getTierAttributes(op); } else if ((0, atomic_operations_2.isWalletAccountTransactionEntityUpdateRedeemEcoupon)(op)) { redeemedCoupons.push(atomic_operations_3.default.WalletAccountTransactionEntity.UpdateRedeemEcoupon.getCouponAttributes(op)); } else if ((0, atomic_operations_2.isWalletTransactionEntityUpdateSettleSettled)(op)) { transactionAttributes = atomic_operations_3.default.WalletTransactionEntity.UpdateSettleSettled.getTransactionAttributes(op); } } if (transactionAttributes === null) { throw new RangeError('WalletTransactionEntity/Update/Settle/Settled not found in POSCONNECT.WALLET.SETTLE'); } const posConnectWalletSettleEventData = { ...(pointsAttributes ? { points: pointsAttributes } : {}), ...(tierAttributes ? { tier: tierAttributes } : {}), ...(transactionAttributes ? { transaction: transactionAttributes } : {}), redeemedCoupons, currencyCode: opts.connectorConfig.configuration.currency, }; return posConnectWalletSettleEventData; } //# sourceMappingURL=posconnect-wallet-settle.js.map