@managesome/eposmatic-toolkit 0.2.323 → 0.2.325
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.
|
@@ -66,12 +66,12 @@ export declare function getSplitCartItemToTwo({ data, orderItemId, courses, list
|
|
|
66
66
|
export declare function getAddItemsToCartData(data: Partial<IOrder>, payload: ISetAddItemToCartActionPayload[], courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
67
67
|
export declare function getUpdateItemInCartData(data: Partial<IOrder>, payload: Partial<IOrderItem>, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
68
68
|
export declare function getUpdateItemsInCartData(data: Partial<IOrder>, payload: Partial<IOrder>[], courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
69
|
-
export declare function getUpdateCartInfoData(data: Partial<IOrder>, payload: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
69
|
+
export declare function getUpdateCartInfoData(data: Partial<IOrder>, payload: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, syncContext?: ICartOfferSyncContext): Partial<IOrder>;
|
|
70
70
|
export declare function getRemoveItemFromCartData(data: Partial<IOrder>, payload: {
|
|
71
71
|
_id: string;
|
|
72
72
|
void_reason?: string;
|
|
73
73
|
}, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
74
|
-
export declare function getUpdatedCartInfoOnInit(data: Partial<IOrder>, order: Partial<IOrder>, courses: ICourse[], platform: PLATFORMS_ENUM | undefined, categories: IOrderCategory[] | undefined, mappedItems: Record<string, IItem>, tenantId: string | undefined, listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
74
|
+
export declare function getUpdatedCartInfoOnInit(data: Partial<IOrder>, order: Partial<IOrder>, courses: ICourse[], platform: PLATFORMS_ENUM | undefined, categories: IOrderCategory[] | undefined, mappedItems: Record<string, IItem>, tenantId: string | undefined, listnerSettings: ICartListnerSettings, offers: IOffer[] | undefined): Partial<IOrder>;
|
|
75
75
|
export declare function getChangeCourseForItemData(data: Partial<IOrder>, itemId: string, new_course_id: string, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
|
|
76
76
|
export declare function getChangeCourseStatusData(data: Partial<IOrder>, course_id: string, called: boolean, courses: ICourse[], listnerSettings: ICartListnerSettings): {
|
|
77
77
|
dinein_details: {
|
|
@@ -1963,12 +1963,12 @@ function getUpdateItemsInCartData(data, payload, courses, listnerSettings) {
|
|
|
1963
1963
|
return newData;
|
|
1964
1964
|
}
|
|
1965
1965
|
/* ======================><====================== */
|
|
1966
|
-
function getUpdateCartInfoData(data, payload, courses, listnerSettings) {
|
|
1966
|
+
function getUpdateCartInfoData(data, payload, courses, listnerSettings, syncContext) {
|
|
1967
1967
|
const order = {
|
|
1968
1968
|
...data,
|
|
1969
1969
|
...payload,
|
|
1970
1970
|
};
|
|
1971
|
-
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
1971
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings, undefined, syncContext);
|
|
1972
1972
|
return newData;
|
|
1973
1973
|
}
|
|
1974
1974
|
/* ======================><====================== */
|
|
@@ -2052,7 +2052,7 @@ function getRemoveItemFromCartData(data, payload, courses, listnerSettings) {
|
|
|
2052
2052
|
return newData;
|
|
2053
2053
|
}
|
|
2054
2054
|
/* ======================>Order Object<====================== */
|
|
2055
|
-
function getUpdatedCartInfoOnInit(data, order, courses, platform, categories, mappedItems, tenantId, listnerSettings) {
|
|
2055
|
+
function getUpdatedCartInfoOnInit(data, order, courses, platform, categories, mappedItems, tenantId, listnerSettings, offers) {
|
|
2056
2056
|
let payload = order;
|
|
2057
2057
|
if (platform && data.platform !== order.platform && categories) {
|
|
2058
2058
|
const newCategories = [];
|
|
@@ -2154,7 +2154,29 @@ function getUpdatedCartInfoOnInit(data, order, courses, platform, categories, ma
|
|
|
2154
2154
|
};
|
|
2155
2155
|
}
|
|
2156
2156
|
const orderData = getUpdateCartInfoData(data, payload, courses, listnerSettings);
|
|
2157
|
-
|
|
2157
|
+
if (platform == null || data.platform === order.platform || offers == null || offers.length === 0) {
|
|
2158
|
+
return orderData;
|
|
2159
|
+
}
|
|
2160
|
+
const redeemedOfferIds = Object.keys(orderData.redeemed_offers ?? {});
|
|
2161
|
+
if (redeemedOfferIds.length === 0) {
|
|
2162
|
+
return orderData;
|
|
2163
|
+
}
|
|
2164
|
+
const offersMap = new Map();
|
|
2165
|
+
for (let i = 0; i < offers.length; i++) {
|
|
2166
|
+
offersMap.set(offers[i]._id, offers[i]);
|
|
2167
|
+
}
|
|
2168
|
+
const invalidRedeemedOfferIds = [];
|
|
2169
|
+
for (let i = 0; i < redeemedOfferIds.length; i++) {
|
|
2170
|
+
const redeemedOfferId = redeemedOfferIds[i];
|
|
2171
|
+
const offer = offersMap.get(redeemedOfferId);
|
|
2172
|
+
if (offer == null || !offer.included_platforms.includes(platform)) {
|
|
2173
|
+
invalidRedeemedOfferIds.push(redeemedOfferId);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
if (invalidRedeemedOfferIds.length === 0) {
|
|
2177
|
+
return orderData;
|
|
2178
|
+
}
|
|
2179
|
+
return getRemoveAllOffersFromCartData(orderData, courses, listnerSettings, invalidRedeemedOfferIds);
|
|
2158
2180
|
}
|
|
2159
2181
|
/* =================================><================================= */
|
|
2160
2182
|
function getChangeCourseForItemData(data, itemId, new_course_id, courses, listnerSettings) {
|
|
@@ -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
|
}
|