UNPKG

@eagleeye-solutions/integration-events-common

Version:
102 lines 4.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPointsAttributesFromWalletAccountTransactionEntity = getPointsAttributesFromWalletAccountTransactionEntity; exports.getBehavioralActionAttributesFromWalletAccountTransactionEntity = getBehavioralActionAttributesFromWalletAccountTransactionEntity; exports.getCouponAttributesFromWalletAccountTransactionEntity = getCouponAttributesFromWalletAccountTransactionEntity; exports.getCouponAttributesWithValueFromWalletAccountTransactionEntity = getCouponAttributesWithValueFromWalletAccountTransactionEntity; exports.getStandardSubscriptionAttributesFromWalletAccountTransactionEntity = getStandardSubscriptionAttributesFromWalletAccountTransactionEntity; const date_fns_1 = require("date-fns"); function getPointsAttributesFromWalletAccountTransactionEntity(walletAccountTransactionEntity) { const account = walletAccountTransactionEntity.objectValue.account; const balances = account.balances; if (balances !== null && balances !== undefined && 'current' in balances && balances.current !== undefined) { return { pointsBalance: balances.current, }; } else { throw new Error('Points balance not available in walletAccountTransactionEntity'); } } function getBehavioralActionAttributesFromWalletAccountTransactionEntity(walletAccountTransactionEntity) { const objectValue = walletAccountTransactionEntity.objectValue; const redeemedValue = objectValue.value; if (walletAccountTransactionEntity.operationType === 'CREATE' && objectValue.account.type === 'BEHAVIOURAL_ACTION' && objectValue.event === 'REDEEM') { return { points: redeemedValue, accountId: objectValue.account.accountId, campaignId: objectValue.account.campaignId, }; } else { throw new Error('Points balance not available in walletAccountTransactionEntity'); } } function getCouponAttributesFromWalletAccountTransactionEntity(walletAccountTransactionEntity) { const account = walletAccountTransactionEntity.objectValue.account; return { accountId: account.accountId, campaignId: account.campaignId, type: account.type, clientType: account.clientType, state: account.state, status: account.status, dateStart: (0, date_fns_1.parseISO)(account.dates.start), dateEnd: account.dates.end ? (0, date_fns_1.parseISO)(account.dates.end) : null, }; } function getCouponAttributesWithValueFromWalletAccountTransactionEntity(entity) { return { ...getCouponAttributesFromWalletAccountTransactionEntity(entity), value: entity.objectValue.value, }; } function getStandardSubscriptionAttributesFromWalletAccountTransactionEntity(entity) { const account = entity.objectValue.account; return { accountId: account.accountId, campaignId: account.campaignId, type: account.type, clientType: account.clientType ?? null, state: account.state, status: account.status, dateStart: (0, date_fns_1.parseISO)(account.dates.start), dateEnd: account.dates.end ? (0, date_fns_1.parseISO)(account.dates.end) : null, }; } exports.default = { CreatePoints: { getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity, getAwardedPointsAttributes: getBehavioralActionAttributesFromWalletAccountTransactionEntity, }, CreateEcoupon: { getCouponAttributes: getCouponAttributesFromWalletAccountTransactionEntity, }, CreateStandardSubscription: { getStandardSubscriptionAttributes: getStandardSubscriptionAttributesFromWalletAccountTransactionEntity, }, UpdateStandardSubscription: { getStandardSubscriptionAttributes: getStandardSubscriptionAttributesFromWalletAccountTransactionEntity, }, UpdateCreditPoints: { getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity, }, UpdateRefundDebitPoints: { getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity, }, UpdateEarnPoints: { getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity, }, UpdateRedeemEcoupon: { getCouponAttributes: getCouponAttributesWithValueFromWalletAccountTransactionEntity, }, UpdateUnredeemEcoupon: { getCouponAttributes: getCouponAttributesWithValueFromWalletAccountTransactionEntity, }, }; //# sourceMappingURL=wallet-account-transaction-entity.js.map