@managesome/eposmatic-toolkit 0.2.272 → 0.2.273
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OFFER_REWARD_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
|
|
2
|
-
import { ICustomer, IDiscountDetails, IOffer, IOrder, IOrderCategory, ITenant, IVoucher } from '../../schemas';
|
|
2
|
+
import { ICustomer, IDiscountDetails, IGiftCard, IOffer, IOrder, IOrderCategory, ITenant, IVoucher } from '../../schemas';
|
|
3
3
|
export declare function getOfferWithPrice<T extends Partial<IOffer> | IOffer>(offer: T, writeable?: boolean): T;
|
|
4
4
|
export declare function convertOffersToWorkableOffers(offers: IOffer[], platform: PLATFORMS_ENUM): IOffer[];
|
|
5
5
|
export declare function calculatePointsRedeemedForOffer(redeemedOffer: IOffer, totalOrderPrice: number, categories: IOrderCategory[] | undefined): number;
|
|
@@ -50,6 +50,7 @@ interface IGetOffersWithStats {
|
|
|
50
50
|
offers: IOffer[];
|
|
51
51
|
customer: Partial<ICustomer> | null;
|
|
52
52
|
vouchers: IVoucher[] | undefined;
|
|
53
|
+
giftCards: IGiftCard[] | undefined;
|
|
53
54
|
customerOfferRedemptionCounts: Record<string, number> | undefined;
|
|
54
55
|
redeemed_offers: IOrder['redeemed_offers'] | null | undefined;
|
|
55
56
|
platform: PLATFORMS_ENUM | undefined;
|
|
@@ -59,7 +60,7 @@ interface IGetOffersWithStats {
|
|
|
59
60
|
currentItemsPrice: number | undefined;
|
|
60
61
|
order_discount_details: IDiscountDetails | null | undefined;
|
|
61
62
|
}
|
|
62
|
-
export declare function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, }: IGetOffersWithStats): {
|
|
63
|
+
export declare function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, }: IGetOffersWithStats): {
|
|
63
64
|
offersWithStats: IOfferWithStats[];
|
|
64
65
|
totalClaimableOffers: number;
|
|
65
66
|
unlockedOffersApplicableTimes: Record<string, number>;
|
|
@@ -672,7 +672,7 @@ function getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers) {
|
|
|
672
672
|
}
|
|
673
673
|
return result;
|
|
674
674
|
}
|
|
675
|
-
function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, }) {
|
|
675
|
+
function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, }) {
|
|
676
676
|
const offersWithStats = [];
|
|
677
677
|
const orderPrice = currentItemsPrice ?? 0;
|
|
678
678
|
const totalDiscount = totalDiscountApplied ?? 0;
|
|
@@ -712,6 +712,18 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
712
712
|
vouchersById.set(voucher._id, voucher);
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
|
+
const giftCardsById = new Map();
|
|
716
|
+
if (giftCards != null) {
|
|
717
|
+
for (let i = 0; i < giftCards.length; i++) {
|
|
718
|
+
const giftCard = giftCards[i];
|
|
719
|
+
const giftCardIsExpired = giftCard.expire_at != null && new Date(giftCard.expire_at).getTime() <= nowTs;
|
|
720
|
+
const giftCardUsesExhausted = giftCard.max_uses != null && giftCard.used_count >= giftCard.max_uses;
|
|
721
|
+
if (!giftCard.active || giftCardIsExpired || giftCardUsesExhausted) {
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
giftCardsById.set(giftCard._id, giftCard);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
715
727
|
const getOfferRedeemedTimes = (offerId) => {
|
|
716
728
|
const redeemedTimes = Number(redeemedOffersById?.[offerId]);
|
|
717
729
|
if (Number.isFinite(redeemedTimes) && redeemedTimes > 0) {
|
|
@@ -935,11 +947,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
935
947
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER) {
|
|
936
948
|
if (offer.reward_voucher == null)
|
|
937
949
|
continue;
|
|
950
|
+
let rewardVoucherLimitExhausted = false;
|
|
951
|
+
if (customerOfferRedemptionCounts != null) {
|
|
952
|
+
const vIds = Object.keys(offer.reward_voucher.voucher_ids);
|
|
953
|
+
for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
|
|
954
|
+
const rewardVoucher = vouchersById.get(vIds[vIdx]);
|
|
955
|
+
if (rewardVoucher != null &&
|
|
956
|
+
rewardVoucher.max_uses_per_customer != null &&
|
|
957
|
+
(customerOfferRedemptionCounts[rewardVoucher._id] ?? 0) >= rewardVoucher.max_uses_per_customer) {
|
|
958
|
+
rewardVoucherLimitExhausted = true;
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
938
963
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
939
964
|
const isRedeemed = redeemedTimes > 0;
|
|
940
965
|
stats.redeemed_times = redeemedTimes;
|
|
941
966
|
stats.applicable_quantity = 1;
|
|
942
|
-
if (
|
|
967
|
+
if (rewardVoucherLimitExhausted) {
|
|
968
|
+
stats.claimable = false;
|
|
969
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
970
|
+
}
|
|
971
|
+
else if (isRedeemed) {
|
|
943
972
|
stats.claimable = false;
|
|
944
973
|
stats.message = 'This offer is redeemed ✅';
|
|
945
974
|
}
|
|
@@ -979,11 +1008,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
979
1008
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS) {
|
|
980
1009
|
if (offer.reward_gift_cards == null)
|
|
981
1010
|
continue;
|
|
1011
|
+
let rewardGiftCardLimitExhausted = false;
|
|
1012
|
+
if (customerOfferRedemptionCounts != null) {
|
|
1013
|
+
const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
|
|
1014
|
+
for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
|
|
1015
|
+
const giftCard = giftCardsById.get(gcIds[gcIdx]);
|
|
1016
|
+
if (giftCard != null &&
|
|
1017
|
+
giftCard.max_uses_per_customer != null &&
|
|
1018
|
+
(customerOfferRedemptionCounts[giftCard._id] ?? 0) >= giftCard.max_uses_per_customer) {
|
|
1019
|
+
rewardGiftCardLimitExhausted = true;
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
982
1024
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
983
1025
|
const isRedeemed = redeemedTimes > 0;
|
|
984
1026
|
stats.redeemed_times = redeemedTimes;
|
|
985
1027
|
stats.applicable_quantity = 1;
|
|
986
|
-
if (
|
|
1028
|
+
if (rewardGiftCardLimitExhausted) {
|
|
1029
|
+
stats.claimable = false;
|
|
1030
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1031
|
+
}
|
|
1032
|
+
else if (isRedeemed) {
|
|
987
1033
|
stats.claimable = false;
|
|
988
1034
|
stats.message = 'This offer is redeemed ✅';
|
|
989
1035
|
}
|
|
@@ -1145,12 +1191,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
1145
1191
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER) {
|
|
1146
1192
|
if (offer.reward_voucher == null)
|
|
1147
1193
|
continue;
|
|
1194
|
+
let rewardVoucherLimitExhausted = false;
|
|
1195
|
+
if (customerOfferRedemptionCounts != null) {
|
|
1196
|
+
const vIds = Object.keys(offer.reward_voucher.voucher_ids);
|
|
1197
|
+
for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
|
|
1198
|
+
const rewardVoucher = vouchersById.get(vIds[vIdx]);
|
|
1199
|
+
if (rewardVoucher != null &&
|
|
1200
|
+
rewardVoucher.max_uses_per_customer != null &&
|
|
1201
|
+
(customerOfferRedemptionCounts[rewardVoucher._id] ?? 0) >= rewardVoucher.max_uses_per_customer) {
|
|
1202
|
+
rewardVoucherLimitExhausted = true;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1148
1207
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1149
1208
|
const isRedeemed = redeemedTimes > 0;
|
|
1150
1209
|
stats.redeemed_times = redeemedTimes;
|
|
1151
1210
|
stats.applicable_quantity = 1;
|
|
1152
|
-
stats.claimable = !isRedeemed;
|
|
1153
|
-
if (
|
|
1211
|
+
stats.claimable = !isRedeemed && !rewardVoucherLimitExhausted;
|
|
1212
|
+
if (rewardVoucherLimitExhausted) {
|
|
1213
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1214
|
+
}
|
|
1215
|
+
else if (isRedeemed) {
|
|
1154
1216
|
stats.message = 'This offer is redeemed ✅';
|
|
1155
1217
|
}
|
|
1156
1218
|
else {
|
|
@@ -1187,12 +1249,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
1187
1249
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS) {
|
|
1188
1250
|
if (offer.reward_gift_cards == null)
|
|
1189
1251
|
continue;
|
|
1252
|
+
let rewardGiftCardLimitExhausted = false;
|
|
1253
|
+
if (customerOfferRedemptionCounts != null) {
|
|
1254
|
+
const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
|
|
1255
|
+
for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
|
|
1256
|
+
const giftCard = giftCardsById.get(gcIds[gcIdx]);
|
|
1257
|
+
if (giftCard != null &&
|
|
1258
|
+
giftCard.max_uses_per_customer != null &&
|
|
1259
|
+
(customerOfferRedemptionCounts[giftCard._id] ?? 0) >= giftCard.max_uses_per_customer) {
|
|
1260
|
+
rewardGiftCardLimitExhausted = true;
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1190
1265
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1191
1266
|
const isRedeemed = redeemedTimes > 0;
|
|
1192
1267
|
stats.redeemed_times = redeemedTimes;
|
|
1193
1268
|
stats.applicable_quantity = 1;
|
|
1194
|
-
stats.claimable = !isRedeemed;
|
|
1195
|
-
if (
|
|
1269
|
+
stats.claimable = !isRedeemed && !rewardGiftCardLimitExhausted;
|
|
1270
|
+
if (rewardGiftCardLimitExhausted) {
|
|
1271
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1272
|
+
}
|
|
1273
|
+
else if (isRedeemed) {
|
|
1196
1274
|
stats.message = 'This offer is redeemed ✅';
|
|
1197
1275
|
}
|
|
1198
1276
|
else {
|
|
@@ -1356,12 +1434,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
1356
1434
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER) {
|
|
1357
1435
|
if (offer.reward_voucher == null)
|
|
1358
1436
|
continue;
|
|
1437
|
+
let rewardVoucherLimitExhausted = false;
|
|
1438
|
+
if (customerOfferRedemptionCounts != null) {
|
|
1439
|
+
const vIds = Object.keys(offer.reward_voucher.voucher_ids);
|
|
1440
|
+
for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
|
|
1441
|
+
const rewardVoucher = vouchersById.get(vIds[vIdx]);
|
|
1442
|
+
if (rewardVoucher != null &&
|
|
1443
|
+
rewardVoucher.max_uses_per_customer != null &&
|
|
1444
|
+
(customerOfferRedemptionCounts[rewardVoucher._id] ?? 0) >= rewardVoucher.max_uses_per_customer) {
|
|
1445
|
+
rewardVoucherLimitExhausted = true;
|
|
1446
|
+
break;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1359
1450
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1360
1451
|
const isRedeemed = redeemedTimes > 0;
|
|
1361
1452
|
stats.redeemed_times = redeemedTimes;
|
|
1362
1453
|
stats.applicable_quantity = 1;
|
|
1363
|
-
stats.claimable = !isRedeemed;
|
|
1364
|
-
if (
|
|
1454
|
+
stats.claimable = !isRedeemed && !rewardVoucherLimitExhausted;
|
|
1455
|
+
if (rewardVoucherLimitExhausted) {
|
|
1456
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1457
|
+
}
|
|
1458
|
+
else if (isRedeemed) {
|
|
1365
1459
|
stats.message = 'This offer is redeemed ✅';
|
|
1366
1460
|
}
|
|
1367
1461
|
else {
|
|
@@ -1398,12 +1492,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
1398
1492
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS) {
|
|
1399
1493
|
if (offer.reward_gift_cards == null)
|
|
1400
1494
|
continue;
|
|
1495
|
+
let rewardGiftCardLimitExhausted = false;
|
|
1496
|
+
if (customerOfferRedemptionCounts != null) {
|
|
1497
|
+
const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
|
|
1498
|
+
for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
|
|
1499
|
+
const giftCard = giftCardsById.get(gcIds[gcIdx]);
|
|
1500
|
+
if (giftCard != null &&
|
|
1501
|
+
giftCard.max_uses_per_customer != null &&
|
|
1502
|
+
(customerOfferRedemptionCounts[giftCard._id] ?? 0) >= giftCard.max_uses_per_customer) {
|
|
1503
|
+
rewardGiftCardLimitExhausted = true;
|
|
1504
|
+
break;
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1401
1508
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1402
1509
|
const isRedeemed = redeemedTimes > 0;
|
|
1403
1510
|
stats.redeemed_times = redeemedTimes;
|
|
1404
1511
|
stats.applicable_quantity = 1;
|
|
1405
|
-
stats.claimable = !isRedeemed;
|
|
1406
|
-
if (
|
|
1512
|
+
stats.claimable = !isRedeemed && !rewardGiftCardLimitExhausted;
|
|
1513
|
+
if (rewardGiftCardLimitExhausted) {
|
|
1514
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1515
|
+
}
|
|
1516
|
+
else if (isRedeemed) {
|
|
1407
1517
|
stats.message = 'This offer is redeemed ✅';
|
|
1408
1518
|
}
|
|
1409
1519
|
else {
|
|
@@ -1568,12 +1678,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
1568
1678
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER) {
|
|
1569
1679
|
if (offer.reward_voucher == null)
|
|
1570
1680
|
continue;
|
|
1681
|
+
let rewardVoucherLimitExhausted = false;
|
|
1682
|
+
if (customerOfferRedemptionCounts != null) {
|
|
1683
|
+
const vIds = Object.keys(offer.reward_voucher.voucher_ids);
|
|
1684
|
+
for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
|
|
1685
|
+
const rewardVoucher = vouchersById.get(vIds[vIdx]);
|
|
1686
|
+
if (rewardVoucher != null &&
|
|
1687
|
+
rewardVoucher.max_uses_per_customer != null &&
|
|
1688
|
+
(customerOfferRedemptionCounts[rewardVoucher._id] ?? 0) >= rewardVoucher.max_uses_per_customer) {
|
|
1689
|
+
rewardVoucherLimitExhausted = true;
|
|
1690
|
+
break;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1571
1694
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1572
1695
|
const isRedeemed = redeemedTimes > 0;
|
|
1573
1696
|
stats.redeemed_times = redeemedTimes;
|
|
1574
1697
|
stats.applicable_quantity = 1;
|
|
1575
|
-
stats.claimable = !isRedeemed;
|
|
1576
|
-
if (
|
|
1698
|
+
stats.claimable = !isRedeemed && !rewardVoucherLimitExhausted;
|
|
1699
|
+
if (rewardVoucherLimitExhausted) {
|
|
1700
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1701
|
+
}
|
|
1702
|
+
else if (isRedeemed) {
|
|
1577
1703
|
stats.message = 'This offer is redeemed ✅';
|
|
1578
1704
|
}
|
|
1579
1705
|
else {
|
|
@@ -1610,12 +1736,28 @@ function getOffersWithStats({ offers, customer, vouchers, customerOfferRedemptio
|
|
|
1610
1736
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS) {
|
|
1611
1737
|
if (offer.reward_gift_cards == null)
|
|
1612
1738
|
continue;
|
|
1739
|
+
let rewardGiftCardLimitExhausted = false;
|
|
1740
|
+
if (customerOfferRedemptionCounts != null) {
|
|
1741
|
+
const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
|
|
1742
|
+
for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
|
|
1743
|
+
const giftCard = giftCardsById.get(gcIds[gcIdx]);
|
|
1744
|
+
if (giftCard != null &&
|
|
1745
|
+
giftCard.max_uses_per_customer != null &&
|
|
1746
|
+
(customerOfferRedemptionCounts[giftCard._id] ?? 0) >= giftCard.max_uses_per_customer) {
|
|
1747
|
+
rewardGiftCardLimitExhausted = true;
|
|
1748
|
+
break;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1613
1752
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1614
1753
|
const isRedeemed = redeemedTimes > 0;
|
|
1615
1754
|
stats.redeemed_times = redeemedTimes;
|
|
1616
1755
|
stats.applicable_quantity = 1;
|
|
1617
|
-
stats.claimable = !isRedeemed;
|
|
1618
|
-
if (
|
|
1756
|
+
stats.claimable = !isRedeemed && !rewardGiftCardLimitExhausted;
|
|
1757
|
+
if (rewardGiftCardLimitExhausted) {
|
|
1758
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
1759
|
+
}
|
|
1760
|
+
else if (isRedeemed) {
|
|
1619
1761
|
stats.message = 'This offer is redeemed ✅';
|
|
1620
1762
|
}
|
|
1621
1763
|
else {
|