@managesome/eposmatic-toolkit 0.2.323 → 0.2.324
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1105,6 +1105,22 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1105
1105
|
let totalClaimableOffers = [];
|
|
1106
1106
|
let totalLoyaltyPointsOfCustomer = null;
|
|
1107
1107
|
const nowTs = Date.now();
|
|
1108
|
+
const isVoucherRewardResourceUnavailable = (voucher) => {
|
|
1109
|
+
if (voucher == null) {
|
|
1110
|
+
return true;
|
|
1111
|
+
}
|
|
1112
|
+
const voucherIsExpired = voucher.expire_at != null && new Date(voucher.expire_at).getTime() <= nowTs;
|
|
1113
|
+
const voucherUsesExhausted = voucher.max_uses != null && voucher.used_count >= voucher.max_uses;
|
|
1114
|
+
return !voucher.active || voucherIsExpired || voucherUsesExhausted;
|
|
1115
|
+
};
|
|
1116
|
+
const isGiftCardRewardResourceUnavailable = (giftCard) => {
|
|
1117
|
+
if (giftCard == null) {
|
|
1118
|
+
return true;
|
|
1119
|
+
}
|
|
1120
|
+
const giftCardIsExpired = giftCard.expire_at != null && new Date(giftCard.expire_at).getTime() <= nowTs;
|
|
1121
|
+
const giftCardUsesExhausted = giftCard.max_uses != null && giftCard.used_count >= giftCard.max_uses;
|
|
1122
|
+
return !giftCard.active || giftCardIsExpired || giftCardUsesExhausted;
|
|
1123
|
+
};
|
|
1108
1124
|
const { voucherCodes: spendableVoucherCodesByCode } = calculateCustomerSpendableVoucherCodes({
|
|
1109
1125
|
customerVoucherCodes: customer?.voucher_codes,
|
|
1110
1126
|
orderDiscountDetails: order_discount_details,
|
|
@@ -1114,24 +1130,24 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1114
1130
|
});
|
|
1115
1131
|
const redeemedOffersById = redeemed_offers ?? null;
|
|
1116
1132
|
const vouchersById = new Map();
|
|
1133
|
+
const allVouchersById = new Map();
|
|
1117
1134
|
if (vouchers != null) {
|
|
1118
1135
|
for (let i = 0; i < vouchers.length; i++) {
|
|
1119
1136
|
const voucher = vouchers[i];
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
if (!voucher.active || voucherIsExpired || voucherUsesExhausted) {
|
|
1137
|
+
allVouchersById.set(voucher._id, voucher);
|
|
1138
|
+
if (isVoucherRewardResourceUnavailable(voucher)) {
|
|
1123
1139
|
continue;
|
|
1124
1140
|
}
|
|
1125
1141
|
vouchersById.set(voucher._id, voucher);
|
|
1126
1142
|
}
|
|
1127
1143
|
}
|
|
1128
1144
|
const giftCardsById = new Map();
|
|
1145
|
+
const allGiftCardsById = new Map();
|
|
1129
1146
|
if (giftCards != null) {
|
|
1130
1147
|
for (let i = 0; i < giftCards.length; i++) {
|
|
1131
1148
|
const giftCard = giftCards[i];
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
if (!giftCard.active || giftCardIsExpired || giftCardUsesExhausted) {
|
|
1149
|
+
allGiftCardsById.set(giftCard._id, giftCard);
|
|
1150
|
+
if (isGiftCardRewardResourceUnavailable(giftCard)) {
|
|
1135
1151
|
continue;
|
|
1136
1152
|
}
|
|
1137
1153
|
giftCardsById.set(giftCard._id, giftCard);
|
|
@@ -1460,24 +1476,31 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1460
1476
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER) {
|
|
1461
1477
|
if (offer.reward_voucher == null)
|
|
1462
1478
|
continue;
|
|
1479
|
+
const vIds = Object.keys(offer.reward_voucher.voucher_ids);
|
|
1480
|
+
let rewardVoucherUnavailable = false;
|
|
1463
1481
|
let rewardVoucherLimitExhausted = false;
|
|
1464
|
-
|
|
1465
|
-
const
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1482
|
+
for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
|
|
1483
|
+
const rewardVoucher = allVouchersById.get(vIds[vIdx]);
|
|
1484
|
+
if (rewardVoucher == null || isVoucherRewardResourceUnavailable(rewardVoucher)) {
|
|
1485
|
+
rewardVoucherUnavailable = true;
|
|
1486
|
+
break;
|
|
1487
|
+
}
|
|
1488
|
+
if (customerOfferRedemptionCounts != null &&
|
|
1489
|
+
rewardVoucher.max_uses_per_customer != null &&
|
|
1490
|
+
(customerOfferRedemptionCounts[rewardVoucher._id] ?? 0) >= rewardVoucher.max_uses_per_customer) {
|
|
1491
|
+
rewardVoucherLimitExhausted = true;
|
|
1492
|
+
break;
|
|
1474
1493
|
}
|
|
1475
1494
|
}
|
|
1476
1495
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1477
1496
|
const isRedeemed = redeemedTimes > 0;
|
|
1478
1497
|
stats.redeemed_times = redeemedTimes;
|
|
1479
1498
|
stats.applicable_quantity = 1;
|
|
1480
|
-
if (
|
|
1499
|
+
if (rewardVoucherUnavailable) {
|
|
1500
|
+
stats.claimable = false;
|
|
1501
|
+
stats.message = '⛔️ This reward is no longer available ⛔️';
|
|
1502
|
+
}
|
|
1503
|
+
else if (rewardVoucherLimitExhausted) {
|
|
1481
1504
|
stats.claimable = false;
|
|
1482
1505
|
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1483
1506
|
}
|
|
@@ -1529,24 +1552,31 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1529
1552
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS) {
|
|
1530
1553
|
if (offer.reward_gift_cards == null)
|
|
1531
1554
|
continue;
|
|
1555
|
+
const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
|
|
1556
|
+
let rewardGiftCardUnavailable = false;
|
|
1532
1557
|
let rewardGiftCardLimitExhausted = false;
|
|
1533
|
-
|
|
1534
|
-
const
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1558
|
+
for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
|
|
1559
|
+
const giftCard = allGiftCardsById.get(gcIds[gcIdx]);
|
|
1560
|
+
if (giftCard == null || isGiftCardRewardResourceUnavailable(giftCard)) {
|
|
1561
|
+
rewardGiftCardUnavailable = true;
|
|
1562
|
+
break;
|
|
1563
|
+
}
|
|
1564
|
+
if (customerOfferRedemptionCounts != null &&
|
|
1565
|
+
giftCard.max_uses_per_customer != null &&
|
|
1566
|
+
(customerOfferRedemptionCounts[giftCard._id] ?? 0) >= giftCard.max_uses_per_customer) {
|
|
1567
|
+
rewardGiftCardLimitExhausted = true;
|
|
1568
|
+
break;
|
|
1543
1569
|
}
|
|
1544
1570
|
}
|
|
1545
1571
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1546
1572
|
const isRedeemed = redeemedTimes > 0;
|
|
1547
1573
|
stats.redeemed_times = redeemedTimes;
|
|
1548
1574
|
stats.applicable_quantity = 1;
|
|
1549
|
-
if (
|
|
1575
|
+
if (rewardGiftCardUnavailable) {
|
|
1576
|
+
stats.claimable = false;
|
|
1577
|
+
stats.message = '⛔️ This reward is no longer available ⛔️';
|
|
1578
|
+
}
|
|
1579
|
+
else if (rewardGiftCardLimitExhausted) {
|
|
1550
1580
|
stats.claimable = false;
|
|
1551
1581
|
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1552
1582
|
}
|