@managesome/eposmatic-toolkit 0.2.295 → 0.2.297

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.
@@ -975,6 +975,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
975
975
  }
976
976
  return Math.min(normalizedUnlockableClaims, getRemainingOfferUsesForCustomer(offerToCheck));
977
977
  };
978
+ const getPathwayMaxRedeemableClaims = ({ offerToCheck, pathwayUnlockableClaims, }) => {
979
+ const normalizedUnlockableClaims = Math.max(0, pathwayUnlockableClaims);
980
+ if (normalizedUnlockableClaims === 0) {
981
+ return 0;
982
+ }
983
+ return Math.min(normalizedUnlockableClaims, getRemainingOfferUsesForCustomer(offerToCheck));
984
+ };
978
985
  for (let i = 0; i < offers.length; i++) {
979
986
  const offer = offers[i];
980
987
  const stats = {
@@ -1181,15 +1188,23 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1181
1188
  continue;
1182
1189
  }
1183
1190
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
1184
- const isRedeemed = redeemedTimes > 0;
1191
+ const maxClaimsPerOrder = offer.pathway_to_unlock_type_orders?.max_claims == null
1192
+ ? Infinity
1193
+ : Math.max(1, offer.pathway_to_unlock_type_orders.max_claims);
1194
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, offer.pathway_to_unlock_type_orders?.total_amount);
1195
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder);
1196
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
1197
+ offerToCheck: offer,
1198
+ pathwayUnlockableClaims: totalUnlockableClaims,
1199
+ });
1200
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
1185
1201
  stats.redeemed_times = redeemedTimes;
1186
- stats.applicable_quantity = 1;
1187
- if (isRedeemed) {
1188
- stats.claimable = false;
1202
+ stats.applicable_quantity = maxRedeemableClaims;
1203
+ stats.claimable = isClaimable;
1204
+ if (!isClaimable) {
1189
1205
  stats.message = 'This offer is redeemed ✅';
1190
1206
  }
1191
1207
  else {
1192
- stats.claimable = true;
1193
1208
  stats.message = `🎉 You have unlocked this offer 🎉`;
1194
1209
  totalClaimableOffers += 1;
1195
1210
  }
@@ -1435,11 +1450,15 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1435
1450
  continue;
1436
1451
  }
1437
1452
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
1438
- const isRedeemed = redeemedTimes > 0;
1453
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
1454
+ offerToCheck: offer,
1455
+ pathwayUnlockableClaims: totalUnlockableClaims,
1456
+ });
1457
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
1439
1458
  stats.redeemed_times = redeemedTimes;
1440
- stats.applicable_quantity = 1;
1441
- stats.claimable = !isRedeemed;
1442
- if (isRedeemed) {
1459
+ stats.applicable_quantity = maxRedeemableClaims;
1460
+ stats.claimable = isClaimable;
1461
+ if (!isClaimable) {
1443
1462
  stats.message = 'This offer is redeemed ✅';
1444
1463
  }
1445
1464
  else {
@@ -1687,11 +1706,15 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1687
1706
  continue;
1688
1707
  }
1689
1708
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
1690
- const isRedeemed = redeemedTimes > 0;
1709
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
1710
+ offerToCheck: offer,
1711
+ pathwayUnlockableClaims: totalUnlockableClaims,
1712
+ });
1713
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
1691
1714
  stats.redeemed_times = redeemedTimes;
1692
- stats.applicable_quantity = 1;
1693
- stats.claimable = !isRedeemed;
1694
- if (isRedeemed) {
1715
+ stats.applicable_quantity = maxRedeemableClaims;
1716
+ stats.claimable = isClaimable;
1717
+ if (!isClaimable) {
1695
1718
  stats.message = 'This offer is redeemed ✅';
1696
1719
  }
1697
1720
  else {
@@ -1948,11 +1971,21 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1948
1971
  continue;
1949
1972
  }
1950
1973
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
1951
- const isRedeemed = redeemedTimes > 0;
1974
+ const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
1975
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
1976
+ const voucherInventoryClaimCap = matchedVoucher != null && !matchedVoucher.is_public
1977
+ ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer)
1978
+ : Infinity;
1979
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
1980
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
1981
+ offerToCheck: offer,
1982
+ pathwayUnlockableClaims: totalUnlockableClaims,
1983
+ });
1984
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
1952
1985
  stats.redeemed_times = redeemedTimes;
1953
- stats.applicable_quantity = 1;
1954
- stats.claimable = !isRedeemed;
1955
- if (isRedeemed) {
1986
+ stats.applicable_quantity = maxRedeemableClaims;
1987
+ stats.claimable = isClaimable;
1988
+ if (!isClaimable) {
1956
1989
  stats.message = 'This offer is redeemed ✅';
1957
1990
  }
1958
1991
  else {
@@ -104,6 +104,7 @@ export interface ISettingsForWeb {
104
104
  instagram_link: ITenant['instagram_link'];
105
105
  twitter_link: ITenant['twitter_link'];
106
106
  tiktok_link: ITenant['tiktok_link'];
107
+ app_version: ITenant['app_version'];
107
108
  }
108
109
  export declare function getSettingsForWeb(settings: ITenant): ISettingsForWeb;
109
110
  export interface ISettingsForPOS {
@@ -200,6 +200,7 @@ function getSettingsForWeb(settings) {
200
200
  instagram_link: settings.instagram_link,
201
201
  twitter_link: settings.twitter_link,
202
202
  tiktok_link: settings.tiktok_link,
203
+ app_version: settings.app_version,
203
204
  };
204
205
  }
205
206
  function getSettingsForPOS(settings) {
@@ -173,6 +173,7 @@ export declare const TenantSchema: Schema<any, import("mongoose").Model<any, any
173
173
  specials_name?: string | null | undefined;
174
174
  receipt_qr_type?: import("../../constants").RECEIPT_QR_CODE_TYPE_ENUM | null | undefined;
175
175
  menu_source?: string | null | undefined;
176
+ app_version?: string | null | undefined;
176
177
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
177
178
  createdAt: NativeDate;
178
179
  updatedAt: NativeDate;
@@ -342,6 +343,7 @@ export declare const TenantSchema: Schema<any, import("mongoose").Model<any, any
342
343
  specials_name?: string | null | undefined;
343
344
  receipt_qr_type?: import("../../constants").RECEIPT_QR_CODE_TYPE_ENUM | null | undefined;
344
345
  menu_source?: string | null | undefined;
346
+ app_version?: string | null | undefined;
345
347
  }>> & import("mongoose").FlatRecord<{
346
348
  createdAt: NativeDate;
347
349
  updatedAt: NativeDate;
@@ -511,6 +513,7 @@ export declare const TenantSchema: Schema<any, import("mongoose").Model<any, any
511
513
  specials_name?: string | null | undefined;
512
514
  receipt_qr_type?: import("../../constants").RECEIPT_QR_CODE_TYPE_ENUM | null | undefined;
513
515
  menu_source?: string | null | undefined;
516
+ app_version?: string | null | undefined;
514
517
  }> & Required<{
515
518
  _id: string;
516
519
  }> & {
@@ -723,6 +723,10 @@ exports.TenantSchema = new mongoose_1.Schema({
723
723
  type: String,
724
724
  required: false,
725
725
  },
726
+ app_version: {
727
+ type: String,
728
+ required: false,
729
+ },
726
730
  // ====><====
727
731
  createdAt: {
728
732
  type: mongoose_1.Schema.Types.Date,
@@ -165,6 +165,7 @@ export interface ITenant {
165
165
  tiktok_link?: string | null;
166
166
  receipt_qr_type?: RECEIPT_QR_CODE_TYPE_ENUM | null;
167
167
  menu_source?: string | null;
168
+ app_version?: string | null;
168
169
  createdAt: Date;
169
170
  updatedAt: Date;
170
171
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.295",
3
+ "version": "0.2.297",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",