UNPKG

@eagleeye-solutions/integration-events-common

Version:
67 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTransactionAttributesFromWalletTransactionEntityUpdate = getTransactionAttributesFromWalletTransactionEntityUpdate; const date_fns_1 = require("date-fns"); function getStoreLocationAttributes(entity) { if ((entity.objectValue.location?.storeId !== undefined && entity.objectValue.location?.storeId !== null) || (entity.objectValue.location?.storeParentId !== undefined && entity.objectValue.location?.storeParentId !== null)) { return { storeId: entity.objectValue.location.storeId ?? null, storeParentId: entity.objectValue.location.storeParentId ?? null, }; } else { return undefined; } } function getProductAttributes(entity) { if (entity.objectValue.basket.contents) { const products = entity.objectValue.basket.contents.map(product => { return { upc: product.upc, description: product.description, itemUnitCost: product.itemUnitCost, totalUnitCostAfterDiscount: product.totalUnitCostAfterDiscount, totalUnitCost: product.totalUnitCost, itemUnitCount: product.itemUnitCount, }; }); return products; } else { return []; } } function getTotalBasketValueAfterDiscount(entity) { return entity.objectValue.basket.summary?.totalBasketValue ?? 0; } function getDiscountsReceived(entity) { if (entity.objectValue.basket.summary?.totalDiscountAmount) { const values = Object.values(entity.objectValue.basket.summary.totalDiscountAmount).filter((x) => Number.isInteger(x)); const discountReceived = values.reduce((total, value) => { return total + value; }, 0); return discountReceived; } else { return 0; } } function getTotalPointsEarned(entity) { return (entity.objectValue.basket.summary?.results?.points.totalPointsGiven ?? 0); } function getTransactionAttributesFromWalletTransactionEntityUpdate(entity) { const transactionAttributes = { storeLocation: getStoreLocationAttributes(entity), products: getProductAttributes(entity), totalBasketValueAfterDiscount: getTotalBasketValueAfterDiscount(entity), discountsReceived: getDiscountsReceived(entity), totalPointsEarned: getTotalPointsEarned(entity), transactionReference: entity.objectValue.reference, transactionDate: (0, date_fns_1.parseISO)(entity.objectValue.transactionDateTime), }; return transactionAttributes; } //# sourceMappingURL=update-settle.js.map