@managesome/eposmatic-toolkit 0.2.289 → 0.2.290

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.
@@ -790,6 +790,25 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
790
790
  totalAmount: currentOrderValue,
791
791
  };
792
792
  };
793
+ const getOfferMaxUsesPerCustomer = (offerToCheck) => {
794
+ if (offerToCheck.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS) {
795
+ return offerToCheck.pathway_to_unlock_type_orders?.max_uses_per_customer ?? null;
796
+ }
797
+ if (offerToCheck.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS) {
798
+ return offerToCheck.pathway_to_unlock_type_items?.max_uses_per_customer ?? null;
799
+ }
800
+ if (offerToCheck.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS) {
801
+ return offerToCheck.pathway_to_unlock_type_points?.max_uses_per_customer ?? null;
802
+ }
803
+ if (offerToCheck.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
804
+ return offerToCheck.pathway_to_unlock_type_vouchers?.max_uses_per_customer ?? null;
805
+ }
806
+ return null;
807
+ };
808
+ const isOfferUsesPerCustomerExhausted = (offerToCheck) => {
809
+ const maxUsesPerCustomer = getOfferMaxUsesPerCustomer(offerToCheck);
810
+ return maxUsesPerCustomer != null && (customerOfferRedemptionCounts?.[offerToCheck._id] ?? 0) >= maxUsesPerCustomer;
811
+ };
793
812
  for (let i = 0; i < offers.length; i++) {
794
813
  const offer = offers[i];
795
814
  const stats = {
@@ -1061,6 +1080,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1061
1080
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
1062
1081
  }
1063
1082
  }
1083
+ if (stats.progress >= 100 && isOfferUsesPerCustomerExhausted(offer)) {
1084
+ if (stats.claimable) {
1085
+ totalClaimableOffers = Math.max(0, totalClaimableOffers - 1);
1086
+ }
1087
+ stats.claimable = false;
1088
+ stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
1089
+ }
1064
1090
  stats.action_hint = getActionHint(offer, stats.claimable);
1065
1091
  offersWithStats.push({
1066
1092
  offer,
@@ -1299,6 +1325,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1299
1325
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
1300
1326
  }
1301
1327
  }
1328
+ if (stats.progress >= 100 && isOfferUsesPerCustomerExhausted(offer)) {
1329
+ if (stats.claimable) {
1330
+ totalClaimableOffers = Math.max(0, totalClaimableOffers - 1);
1331
+ }
1332
+ stats.claimable = false;
1333
+ stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
1334
+ }
1302
1335
  stats.action_hint = getActionHint(offer, stats.claimable);
1303
1336
  offersWithStats.push({
1304
1337
  offer,
@@ -1540,6 +1573,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1540
1573
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
1541
1574
  }
1542
1575
  }
1576
+ if (stats.progress >= 100 && isOfferUsesPerCustomerExhausted(offer)) {
1577
+ if (stats.claimable) {
1578
+ totalClaimableOffers = Math.max(0, totalClaimableOffers - 1);
1579
+ }
1580
+ stats.claimable = false;
1581
+ stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
1582
+ }
1543
1583
  stats.action_hint = getActionHint(offer, stats.claimable);
1544
1584
  offersWithStats.push({
1545
1585
  offer,
@@ -1783,6 +1823,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1783
1823
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
1784
1824
  }
1785
1825
  }
1826
+ if (stats.progress >= 100 && isOfferUsesPerCustomerExhausted(offer)) {
1827
+ if (stats.claimable) {
1828
+ totalClaimableOffers = Math.max(0, totalClaimableOffers - 1);
1829
+ }
1830
+ stats.claimable = false;
1831
+ stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
1832
+ }
1786
1833
  stats.action_hint = getActionHint(offer, stats.claimable);
1787
1834
  offersWithStats.push({
1788
1835
  offer,
@@ -368,6 +368,7 @@ export declare const OfferSchema: Schema<any, import("mongoose").Model<any, any,
368
368
  exclusive_refs: string[];
369
369
  total_amount: number;
370
370
  item_ids?: import("mongoose").Types.ObjectId[] | null | undefined;
371
+ max_uses_per_customer?: number | null | undefined;
371
372
  max_claims?: number | null | undefined;
372
373
  min_same_item_quantity?: number | null | undefined;
373
374
  max_same_item_quantity?: number | null | undefined;
@@ -375,20 +376,23 @@ export declare const OfferSchema: Schema<any, import("mongoose").Model<any, any,
375
376
  } | null | undefined;
376
377
  pathway_to_unlock_type_orders?: {
377
378
  total_amount: number;
379
+ scope: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM;
378
380
  min_num_of_orders: number;
379
381
  max_amount?: number | null | undefined;
380
- scope?: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM | null | undefined;
382
+ max_uses_per_customer?: number | null | undefined;
381
383
  max_num_of_orders?: number | null | undefined;
382
384
  } | null | undefined;
383
385
  pathway_to_unlock_type_points?: {
384
386
  num_of_points: number;
385
387
  total_amount: number;
388
+ max_uses_per_customer?: number | null | undefined;
386
389
  max_claims?: number | null | undefined;
387
390
  } | null | undefined;
388
391
  pathway_to_unlock_type_vouchers?: {
389
392
  voucher_ids: import("mongoose").Types.ObjectId[];
390
393
  total_amount: number;
391
394
  max_amount?: number | null | undefined;
395
+ max_uses_per_customer?: number | null | undefined;
392
396
  } | null | undefined;
393
397
  reward_gift_cards?: {
394
398
  gift_card_ids: Map<string, number>;
@@ -757,6 +761,7 @@ export declare const OfferSchema: Schema<any, import("mongoose").Model<any, any,
757
761
  exclusive_refs: string[];
758
762
  total_amount: number;
759
763
  item_ids?: import("mongoose").Types.ObjectId[] | null | undefined;
764
+ max_uses_per_customer?: number | null | undefined;
760
765
  max_claims?: number | null | undefined;
761
766
  min_same_item_quantity?: number | null | undefined;
762
767
  max_same_item_quantity?: number | null | undefined;
@@ -764,20 +769,23 @@ export declare const OfferSchema: Schema<any, import("mongoose").Model<any, any,
764
769
  } | null | undefined;
765
770
  pathway_to_unlock_type_orders?: {
766
771
  total_amount: number;
772
+ scope: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM;
767
773
  min_num_of_orders: number;
768
774
  max_amount?: number | null | undefined;
769
- scope?: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM | null | undefined;
775
+ max_uses_per_customer?: number | null | undefined;
770
776
  max_num_of_orders?: number | null | undefined;
771
777
  } | null | undefined;
772
778
  pathway_to_unlock_type_points?: {
773
779
  num_of_points: number;
774
780
  total_amount: number;
781
+ max_uses_per_customer?: number | null | undefined;
775
782
  max_claims?: number | null | undefined;
776
783
  } | null | undefined;
777
784
  pathway_to_unlock_type_vouchers?: {
778
785
  voucher_ids: import("mongoose").Types.ObjectId[];
779
786
  total_amount: number;
780
787
  max_amount?: number | null | undefined;
788
+ max_uses_per_customer?: number | null | undefined;
781
789
  } | null | undefined;
782
790
  reward_gift_cards?: {
783
791
  gift_card_ids: Map<string, number>;
@@ -1146,6 +1154,7 @@ export declare const OfferSchema: Schema<any, import("mongoose").Model<any, any,
1146
1154
  exclusive_refs: string[];
1147
1155
  total_amount: number;
1148
1156
  item_ids?: import("mongoose").Types.ObjectId[] | null | undefined;
1157
+ max_uses_per_customer?: number | null | undefined;
1149
1158
  max_claims?: number | null | undefined;
1150
1159
  min_same_item_quantity?: number | null | undefined;
1151
1160
  max_same_item_quantity?: number | null | undefined;
@@ -1153,20 +1162,23 @@ export declare const OfferSchema: Schema<any, import("mongoose").Model<any, any,
1153
1162
  } | null | undefined;
1154
1163
  pathway_to_unlock_type_orders?: {
1155
1164
  total_amount: number;
1165
+ scope: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM;
1156
1166
  min_num_of_orders: number;
1157
1167
  max_amount?: number | null | undefined;
1158
- scope?: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM | null | undefined;
1168
+ max_uses_per_customer?: number | null | undefined;
1159
1169
  max_num_of_orders?: number | null | undefined;
1160
1170
  } | null | undefined;
1161
1171
  pathway_to_unlock_type_points?: {
1162
1172
  num_of_points: number;
1163
1173
  total_amount: number;
1174
+ max_uses_per_customer?: number | null | undefined;
1164
1175
  max_claims?: number | null | undefined;
1165
1176
  } | null | undefined;
1166
1177
  pathway_to_unlock_type_vouchers?: {
1167
1178
  voucher_ids: import("mongoose").Types.ObjectId[];
1168
1179
  total_amount: number;
1169
1180
  max_amount?: number | null | undefined;
1181
+ max_uses_per_customer?: number | null | undefined;
1170
1182
  } | null | undefined;
1171
1183
  reward_gift_cards?: {
1172
1184
  gift_card_ids: Map<string, number>;
@@ -9,6 +9,11 @@ const PathwayToUnlockTypeItemsSchema = new mongoose_1.Schema({
9
9
  type: Number,
10
10
  required: true,
11
11
  },
12
+ max_uses_per_customer: {
13
+ type: Number,
14
+ required: false,
15
+ default: null,
16
+ },
12
17
  max_claims: {
13
18
  type: Number,
14
19
  required: false,
@@ -56,9 +61,13 @@ const PathwayToUnlockTypeOrdersSchema = new mongoose_1.Schema({
56
61
  scope: {
57
62
  type: String,
58
63
  enum: constants_1.ALL_PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPES,
59
- required: false,
60
64
  default: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
61
65
  },
66
+ max_uses_per_customer: {
67
+ type: Number,
68
+ required: false,
69
+ default: null,
70
+ },
62
71
  min_num_of_orders: {
63
72
  type: Number,
64
73
  required: true,
@@ -90,6 +99,11 @@ const PathwayToUnlockTypePointsSchema = new mongoose_1.Schema({
90
99
  type: Number,
91
100
  required: true,
92
101
  },
102
+ max_uses_per_customer: {
103
+ type: Number,
104
+ required: false,
105
+ default: null,
106
+ },
93
107
  max_claims: {
94
108
  type: Number,
95
109
  required: false,
@@ -109,6 +123,11 @@ const PathwayToUnlockTypeVouchersSchema = new mongoose_1.Schema({
109
123
  required: false,
110
124
  default: null,
111
125
  },
126
+ max_uses_per_customer: {
127
+ type: Number,
128
+ required: false,
129
+ default: null,
130
+ },
112
131
  voucher_ids: {
113
132
  type: [mongoose_1.Schema.Types.ObjectId],
114
133
  required: true,
@@ -1,7 +1,8 @@
1
1
  import { MYSTERY_GIFT_TYPE_ENUM, OFFER_REWARD_TYPE_ENUM, PATHWAY_TO_UNLOCK_TYPE_ENUM, PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM, PLATFORMS_ENUM } from '../../constants';
2
2
  import { IItemSpecialHour } from './common';
3
3
  export interface IPathwayToUnlockTypeOrders {
4
- scope?: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM;
4
+ scope: PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM;
5
+ max_uses_per_customer: number | null;
5
6
  min_num_of_orders: number;
6
7
  max_num_of_orders: number | null;
7
8
  total_amount: number;
@@ -9,6 +10,7 @@ export interface IPathwayToUnlockTypeOrders {
9
10
  }
10
11
  export interface IPathwayToUnlockTypeItems {
11
12
  num_of_items: number;
13
+ max_uses_per_customer: number | null;
12
14
  max_claims: number | null;
13
15
  min_same_item_quantity: number | null;
14
16
  max_same_item_quantity: number | null;
@@ -21,11 +23,13 @@ export interface IPathwayToUnlockTypeItems {
21
23
  export interface IPathwayToUnlockTypePoints {
22
24
  num_of_points: number;
23
25
  total_amount: number;
26
+ max_uses_per_customer: number | null;
24
27
  max_claims: number | null;
25
28
  }
26
29
  export interface IPathwayToUnlockTypeVouchers {
27
30
  total_amount: number;
28
31
  max_amount: number | null;
32
+ max_uses_per_customer: number | null;
29
33
  voucher_ids: string[];
30
34
  }
31
35
  type IOfferPathwayItems = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.289",
3
+ "version": "0.2.290",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",