@managesome/eposmatic-toolkit 0.2.306 → 0.2.307
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.
- package/lib/helpers/order/generate-order.js +32 -4
- package/lib/helpers/store/cart-actions.d.ts +1 -1
- package/lib/helpers/store/cart-actions.js +46 -11
- package/lib/helpers/utils/offers-helpers.js +4 -4
- package/lib/schemas/models/order.d.ts +24 -3
- package/lib/schemas/models/order.js +28 -2
- package/lib/schemas/types/order.d.ts +11 -2
- package/package.json +1 -1
|
@@ -36,6 +36,30 @@ function getOrderTakeAwayDetails(takeaway_details) {
|
|
|
36
36
|
estimated_takeaway_time: takeaway_details.estimated_takeaway_time != null ? new Date(takeaway_details.estimated_takeaway_time) : null,
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
function getOrderWalletRedemptions(walletRedemptions) {
|
|
40
|
+
if (walletRedemptions == null)
|
|
41
|
+
return null;
|
|
42
|
+
const normalizedWalletRedemptions = {};
|
|
43
|
+
const cashbackAmount = Number(walletRedemptions.cashback_amount);
|
|
44
|
+
if (Number.isFinite(cashbackAmount) && cashbackAmount > 0) {
|
|
45
|
+
normalizedWalletRedemptions.cashback_amount = cashbackAmount;
|
|
46
|
+
}
|
|
47
|
+
const giftCardRedemption = walletRedemptions.gift_cards;
|
|
48
|
+
if (giftCardRedemption != null) {
|
|
49
|
+
const giftCardId = giftCardRedemption.gift_card_id?.toString().trim();
|
|
50
|
+
const valueRedeemed = Number(giftCardRedemption.value_redeemed);
|
|
51
|
+
if (giftCardId != null && giftCardId.length > 0 && Number.isFinite(valueRedeemed) && valueRedeemed > 0) {
|
|
52
|
+
normalizedWalletRedemptions.gift_cards = {
|
|
53
|
+
gift_card_id: giftCardId,
|
|
54
|
+
value_redeemed: valueRedeemed,
|
|
55
|
+
...(giftCardRedemption.mystery_gift_type != null
|
|
56
|
+
? { mystery_gift_type: giftCardRedemption.mystery_gift_type }
|
|
57
|
+
: {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return Object.keys(normalizedWalletRedemptions).length > 0 ? normalizedWalletRedemptions : null;
|
|
62
|
+
}
|
|
39
63
|
function generateOrderCategories(categories) {
|
|
40
64
|
if (!categories)
|
|
41
65
|
return [];
|
|
@@ -143,7 +167,8 @@ function generateOrderOnCreate(order, withIterations) {
|
|
|
143
167
|
if (!newOrder.redeemed_offers || Object.keys(newOrder.redeemed_offers).length === 0) {
|
|
144
168
|
delete newOrder.redeemed_offers;
|
|
145
169
|
}
|
|
146
|
-
|
|
170
|
+
newOrder.wallet_redemptions = getOrderWalletRedemptions(newOrder.wallet_redemptions);
|
|
171
|
+
if (newOrder.wallet_redemptions == null) {
|
|
147
172
|
delete newOrder.wallet_redemptions;
|
|
148
173
|
}
|
|
149
174
|
if (!newOrder.surcharge) {
|
|
@@ -333,9 +358,12 @@ function generateOrderOnUpdate(partialUpdatedOrder) {
|
|
|
333
358
|
delete set.wallet_redemptions;
|
|
334
359
|
unset['wallet_redemptions'] = '';
|
|
335
360
|
}
|
|
336
|
-
else if (set.wallet_redemptions != null
|
|
337
|
-
|
|
338
|
-
|
|
361
|
+
else if (set.wallet_redemptions != null) {
|
|
362
|
+
set.wallet_redemptions = getOrderWalletRedemptions(set.wallet_redemptions);
|
|
363
|
+
if (set.wallet_redemptions == null) {
|
|
364
|
+
delete set.wallet_redemptions;
|
|
365
|
+
unset['wallet_redemptions'] = '';
|
|
366
|
+
}
|
|
339
367
|
}
|
|
340
368
|
if (set.surcharge === 0) {
|
|
341
369
|
delete set.surcharge;
|
|
@@ -109,7 +109,7 @@ export declare function getChangeCourseStatusData(data: Partial<IOrder>, course_
|
|
|
109
109
|
payment_method_expected?: import("../../constants").PAYMENT_METHOD_EXPECTED_ENUM | undefined;
|
|
110
110
|
order_taker_details?: (import("../../schemas").IStaffDetails | null) | undefined;
|
|
111
111
|
redeemed_offers?: (Record<string, number> | null) | undefined;
|
|
112
|
-
wallet_redemptions?: (
|
|
112
|
+
wallet_redemptions?: (import("../../schemas").IWalletRedemptions | null) | undefined;
|
|
113
113
|
order_settled_at?: Date | undefined;
|
|
114
114
|
order_settled_at_mins?: number | undefined;
|
|
115
115
|
createdAt_mins?: number | undefined;
|
|
@@ -388,6 +388,29 @@ function getNormalizedRedeemedOffersMap(redeemedOffers) {
|
|
|
388
388
|
}
|
|
389
389
|
return Object.keys(normalizedRedeemedOffers).length > 0 ? normalizedRedeemedOffers : null;
|
|
390
390
|
}
|
|
391
|
+
function isRedeemedOffersMapNormalized(redeemedOffers) {
|
|
392
|
+
if (redeemedOffers == null) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
const normalizedRedeemedOffers = getNormalizedRedeemedOffersMap(redeemedOffers);
|
|
396
|
+
const rawOfferIds = Object.keys(redeemedOffers);
|
|
397
|
+
const normalizedOfferIds = Object.keys(normalizedRedeemedOffers ?? {});
|
|
398
|
+
if (rawOfferIds.length !== normalizedOfferIds.length) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
for (let i = 0; i < rawOfferIds.length; i++) {
|
|
402
|
+
const rawOfferId = rawOfferIds[i];
|
|
403
|
+
const normalizedOfferId = getNormalizedOfferId(rawOfferId);
|
|
404
|
+
const safeCount = toPositiveInteger(redeemedOffers[rawOfferId], 0);
|
|
405
|
+
if (normalizedOfferId == null || rawOfferId !== normalizedOfferId || safeCount <= 0) {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
if ((normalizedRedeemedOffers?.[normalizedOfferId] ?? 0) !== safeCount) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
391
414
|
function areRedeemedOffersEqual(currentRedeemedOffers, nextRedeemedOffers) {
|
|
392
415
|
const normalizedCurrentRedeemedOffers = getNormalizedRedeemedOffersMap(currentRedeemedOffers);
|
|
393
416
|
const normalizedNextRedeemedOffers = getNormalizedRedeemedOffersMap(nextRedeemedOffers);
|
|
@@ -465,11 +488,13 @@ function getReconciledRedeemedOffersMap({ existingRedeemedOffers, categories, of
|
|
|
465
488
|
}
|
|
466
489
|
const existingRedeemedTimes = toPositiveInteger(nextRedeemedOffers[normalizedOfferId], 0);
|
|
467
490
|
if (existingRedeemedTimes <= 0) {
|
|
491
|
+
delete nextRedeemedOffers[normalizedOfferId];
|
|
468
492
|
continue;
|
|
469
493
|
}
|
|
470
494
|
const maxApplicableTimes = toPositiveInteger(unlockedOffersApplicableTimes?.[offer._id], 0);
|
|
471
495
|
if (maxApplicableTimes <= 0) {
|
|
472
|
-
|
|
496
|
+
// Preserve non-item claims as positive claimed-times when unlock state is temporarily unavailable.
|
|
497
|
+
nextRedeemedOffers[normalizedOfferId] = existingRedeemedTimes;
|
|
473
498
|
continue;
|
|
474
499
|
}
|
|
475
500
|
nextRedeemedOffers[normalizedOfferId] = Math.min(existingRedeemedTimes, maxApplicableTimes);
|
|
@@ -483,16 +508,23 @@ function getNormalizedWalletRedemptionsMap(walletRedemptions) {
|
|
|
483
508
|
if (walletRedemptions == null)
|
|
484
509
|
return null;
|
|
485
510
|
const normalized = {};
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
511
|
+
const cashbackAmount = Number(walletRedemptions.cashback_amount);
|
|
512
|
+
if (Number.isFinite(cashbackAmount) && cashbackAmount > 0) {
|
|
513
|
+
normalized.cashback_amount = cashbackAmount;
|
|
514
|
+
}
|
|
515
|
+
const giftCardRedemption = walletRedemptions.gift_cards;
|
|
516
|
+
if (giftCardRedemption != null) {
|
|
517
|
+
const giftCardId = giftCardRedemption.gift_card_id?.toString().trim();
|
|
518
|
+
const valueRedeemed = Number(giftCardRedemption.value_redeemed);
|
|
519
|
+
if (giftCardId != null && giftCardId.length > 0 && Number.isFinite(valueRedeemed) && valueRedeemed > 0) {
|
|
520
|
+
normalized.gift_cards = {
|
|
521
|
+
gift_card_id: giftCardId,
|
|
522
|
+
value_redeemed: valueRedeemed,
|
|
523
|
+
...(giftCardRedemption.mystery_gift_type != null
|
|
524
|
+
? { mystery_gift_type: giftCardRedemption.mystery_gift_type }
|
|
525
|
+
: {}),
|
|
526
|
+
};
|
|
527
|
+
}
|
|
496
528
|
}
|
|
497
529
|
return Object.keys(normalized).length > 0 ? normalized : null;
|
|
498
530
|
}
|
|
@@ -2132,6 +2164,9 @@ offers) {
|
|
|
2132
2164
|
const orderLevelDiscountBaseAmount = (0, utils_1.getOrderSubtotalFromCategories)(categories);
|
|
2133
2165
|
let order_discount_details = data.order_discount_details;
|
|
2134
2166
|
let redeemed_offers = getNormalizedRedeemedOffersMap(data.redeemed_offers);
|
|
2167
|
+
if (!isRedeemedOffersMapNormalized(data.redeemed_offers)) {
|
|
2168
|
+
hasChanges = true;
|
|
2169
|
+
}
|
|
2135
2170
|
const redeemedOffersPresenceMap = getReconciledRedeemedOffersMap({
|
|
2136
2171
|
existingRedeemedOffers: redeemed_offers,
|
|
2137
2172
|
categories,
|
|
@@ -1317,7 +1317,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1317
1317
|
const totalItemsSelected = totalOfferItemsSelected + bachelorItems;
|
|
1318
1318
|
const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
1319
1319
|
const unlockTimesForItems = Math.floor(totalItemsSelected / (num_of_items || 1));
|
|
1320
|
-
const unlockTimesForAmount = Math.floor(orderValue /
|
|
1320
|
+
const unlockTimesForAmount = total_amount != null && total_amount > 0 ? Math.floor(orderValue / total_amount) : unlockTimesForItems;
|
|
1321
1321
|
const totalUnlockableClaims = Math.min(unlockTimesForItems, unlockTimesForAmount, maxClaimsPerOrder);
|
|
1322
1322
|
const itemsProgress = getPreUnlockProgressPercentage(bachelorItems, num_of_items || 1);
|
|
1323
1323
|
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount || 1);
|
|
@@ -1603,7 +1603,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1603
1603
|
}
|
|
1604
1604
|
if (stats.progress >= 100) {
|
|
1605
1605
|
const pointBurnTimes = Math.floor(effectiveLoyaltyPointsForCurrentOffer / (num_of_points || 1));
|
|
1606
|
-
const amountTimes = Math.floor(orderValue /
|
|
1606
|
+
const amountTimes = total_amount != null && total_amount > 0 ? Math.floor(orderValue / total_amount) : pointBurnTimes;
|
|
1607
1607
|
const totalUnlockableClaims = Math.min(pointBurnTimes, amountTimes, maxClaimsPerOrder);
|
|
1608
1608
|
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT) {
|
|
1609
1609
|
if (offer.reward_discount == null)
|
|
@@ -1660,7 +1660,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1660
1660
|
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
1661
1661
|
}
|
|
1662
1662
|
else {
|
|
1663
|
-
stats.message = `This offer is redeemed
|
|
1663
|
+
stats.message = redeemedTimes > 0 ? `This offer is redeemed ✅` : `🎉 You have unlocked this offer 🎉`;
|
|
1664
1664
|
}
|
|
1665
1665
|
unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
|
|
1666
1666
|
}
|
|
@@ -1798,7 +1798,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1798
1798
|
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
1799
1799
|
}
|
|
1800
1800
|
else {
|
|
1801
|
-
stats.message = `This offer is redeemed
|
|
1801
|
+
stats.message = redeemedTimes > 0 ? `This offer is redeemed ✅` : `🎉 You have unlocked this offer 🎉`;
|
|
1802
1802
|
}
|
|
1803
1803
|
unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
|
|
1804
1804
|
}
|
|
@@ -5185,7 +5185,14 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
5185
5185
|
is_gst_inclusive?: boolean | null | undefined;
|
|
5186
5186
|
tax_invoice_provider_charges?: number | null | undefined;
|
|
5187
5187
|
redeemed_offers?: Map<string, number> | null | undefined;
|
|
5188
|
-
wallet_redemptions?:
|
|
5188
|
+
wallet_redemptions?: {
|
|
5189
|
+
gift_cards?: {
|
|
5190
|
+
gift_card_id: string;
|
|
5191
|
+
value_redeemed: number;
|
|
5192
|
+
mystery_gift_type?: import("../../constants").GIFT_CARD_REWARD_TYPE_ENUM | null | undefined;
|
|
5193
|
+
} | null | undefined;
|
|
5194
|
+
cashback_amount?: number | null | undefined;
|
|
5195
|
+
} | null | undefined;
|
|
5189
5196
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
5190
5197
|
createdAt: NativeDate;
|
|
5191
5198
|
updatedAt: NativeDate;
|
|
@@ -10284,7 +10291,14 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
10284
10291
|
is_gst_inclusive?: boolean | null | undefined;
|
|
10285
10292
|
tax_invoice_provider_charges?: number | null | undefined;
|
|
10286
10293
|
redeemed_offers?: Map<string, number> | null | undefined;
|
|
10287
|
-
wallet_redemptions?:
|
|
10294
|
+
wallet_redemptions?: {
|
|
10295
|
+
gift_cards?: {
|
|
10296
|
+
gift_card_id: string;
|
|
10297
|
+
value_redeemed: number;
|
|
10298
|
+
mystery_gift_type?: import("../../constants").GIFT_CARD_REWARD_TYPE_ENUM | null | undefined;
|
|
10299
|
+
} | null | undefined;
|
|
10300
|
+
cashback_amount?: number | null | undefined;
|
|
10301
|
+
} | null | undefined;
|
|
10288
10302
|
}>> & import("mongoose").FlatRecord<{
|
|
10289
10303
|
createdAt: NativeDate;
|
|
10290
10304
|
updatedAt: NativeDate;
|
|
@@ -15383,7 +15397,14 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
15383
15397
|
is_gst_inclusive?: boolean | null | undefined;
|
|
15384
15398
|
tax_invoice_provider_charges?: number | null | undefined;
|
|
15385
15399
|
redeemed_offers?: Map<string, number> | null | undefined;
|
|
15386
|
-
wallet_redemptions?:
|
|
15400
|
+
wallet_redemptions?: {
|
|
15401
|
+
gift_cards?: {
|
|
15402
|
+
gift_card_id: string;
|
|
15403
|
+
value_redeemed: number;
|
|
15404
|
+
mystery_gift_type?: import("../../constants").GIFT_CARD_REWARD_TYPE_ENUM | null | undefined;
|
|
15405
|
+
} | null | undefined;
|
|
15406
|
+
cashback_amount?: number | null | undefined;
|
|
15407
|
+
} | null | undefined;
|
|
15387
15408
|
}> & Required<{
|
|
15388
15409
|
_id: import("mongoose").Types.ObjectId;
|
|
15389
15410
|
}> & {
|
|
@@ -228,6 +228,33 @@ const DiscountDetailsSchema = new mongoose_1.Schema({
|
|
|
228
228
|
required: true,
|
|
229
229
|
},
|
|
230
230
|
}, { _id: false, minimize: false });
|
|
231
|
+
const GiftCardRedemptionSchema = new mongoose_1.Schema({
|
|
232
|
+
gift_card_id: {
|
|
233
|
+
type: String,
|
|
234
|
+
required: true,
|
|
235
|
+
},
|
|
236
|
+
mystery_gift_type: {
|
|
237
|
+
type: String,
|
|
238
|
+
enum: constants_1.ALL_GIFT_CARD_REWARD_TYPES,
|
|
239
|
+
required: false,
|
|
240
|
+
},
|
|
241
|
+
value_redeemed: {
|
|
242
|
+
type: Number,
|
|
243
|
+
min: 0,
|
|
244
|
+
required: true,
|
|
245
|
+
},
|
|
246
|
+
}, { _id: false, minimize: false });
|
|
247
|
+
const WalletRedemptionsSchema = new mongoose_1.Schema({
|
|
248
|
+
cashback_amount: {
|
|
249
|
+
type: Number,
|
|
250
|
+
min: 0,
|
|
251
|
+
required: false,
|
|
252
|
+
},
|
|
253
|
+
gift_cards: {
|
|
254
|
+
type: GiftCardRedemptionSchema,
|
|
255
|
+
required: false,
|
|
256
|
+
},
|
|
257
|
+
}, { _id: false, minimize: false });
|
|
231
258
|
const OptionsSchema = new mongoose_1.Schema({
|
|
232
259
|
_id: {
|
|
233
260
|
type: String,
|
|
@@ -814,8 +841,7 @@ exports.OrderSchema = new mongoose_1.Schema({
|
|
|
814
841
|
required: false,
|
|
815
842
|
},
|
|
816
843
|
wallet_redemptions: {
|
|
817
|
-
type:
|
|
818
|
-
of: Number,
|
|
844
|
+
type: WalletRedemptionsSchema,
|
|
819
845
|
required: false,
|
|
820
846
|
},
|
|
821
847
|
order_settled_at: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ORDER_ITEM_TYPE_ENUM, ORDER_STATUS_ENUM, PAYMENT_METHOD_EXPECTED_ENUM, PAYMENT_PROVIDERS_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM, PLATFORMS_ENUM, SPLIT_BILL_TYPE_ENUM } from '../../constants';
|
|
1
|
+
import { GIFT_CARD_REWARD_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM, ORDER_STATUS_ENUM, PAYMENT_METHOD_EXPECTED_ENUM, PAYMENT_PROVIDERS_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM, PLATFORMS_ENUM, SPLIT_BILL_TYPE_ENUM } from '../../constants';
|
|
2
2
|
export interface IOrderCourse {
|
|
3
3
|
name: string;
|
|
4
4
|
course_id: string;
|
|
@@ -121,6 +121,15 @@ export interface IOrderDineInDetails {
|
|
|
121
121
|
export interface IOrderTakeawayDetails {
|
|
122
122
|
estimated_takeaway_time: Date | null;
|
|
123
123
|
}
|
|
124
|
+
export interface IGiftCardRedemption {
|
|
125
|
+
gift_card_id: string;
|
|
126
|
+
mystery_gift_type?: GIFT_CARD_REWARD_TYPE_ENUM | null;
|
|
127
|
+
value_redeemed: number;
|
|
128
|
+
}
|
|
129
|
+
export interface IWalletRedemptions {
|
|
130
|
+
cashback_amount?: number | null;
|
|
131
|
+
gift_cards?: IGiftCardRedemption | null;
|
|
132
|
+
}
|
|
124
133
|
interface CommonOptionalFields {
|
|
125
134
|
delivery_details?: IOrderDeliveryDetails | null;
|
|
126
135
|
dinein_details?: IOrderDineInDetails | null;
|
|
@@ -223,7 +232,7 @@ export interface IOrder extends CommonOptionalFields {
|
|
|
223
232
|
payment_method_expected?: PAYMENT_METHOD_EXPECTED_ENUM;
|
|
224
233
|
order_taker_details?: IStaffDetails | null;
|
|
225
234
|
redeemed_offers?: Record<string, number> | null;
|
|
226
|
-
wallet_redemptions?:
|
|
235
|
+
wallet_redemptions?: IWalletRedemptions | null;
|
|
227
236
|
order_settled_at: Date;
|
|
228
237
|
order_settled_at_mins: number;
|
|
229
238
|
createdAt_mins: number;
|