@timardex/cluemart-server-shared 1.0.305 → 1.0.308

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/dist/index.cjs CHANGED
@@ -7415,7 +7415,6 @@ var AFFILIATE_DETAILS_FIELDS_FRAGMENT = gql`
7415
7415
  location {
7416
7416
  ...LocationFields
7417
7417
  }
7418
- region
7419
7418
  socialMedia {
7420
7419
  ...SocialMediaFields
7421
7420
  }
@@ -9300,7 +9299,6 @@ var affiliateDetailsSchema = new MongooseSchema25(
9300
9299
  required: true,
9301
9300
  type: String
9302
9301
  },
9303
- region: { required: true, type: String },
9304
9302
  socialMedia: { required: false, type: [SocialMediaTypeSchema] },
9305
9303
  termsAgreement: { required: true, type: termsAgreementSchema }
9306
9304
  },
@@ -9423,7 +9421,7 @@ var SHARE_RESOURCE_LABEL2 = {
9423
9421
  school: "School"
9424
9422
  };
9425
9423
 
9426
- // node_modules/@timardex/cluemart-shared/dist/chunk-OBZTGPBJ.mjs
9424
+ // node_modules/@timardex/cluemart-shared/dist/chunk-QMJB5OJ4.mjs
9427
9425
  var PROMO_CODE_PREFIX2 = "CM-";
9428
9426
  var OBJECT_ID_PATH_SEGMENT2 = "[a-f0-9]{24}";
9429
9427
  var OBJECT_ID_PATH_SEGMENT_END2 = `${OBJECT_ID_PATH_SEGMENT2}$`;
@@ -9525,7 +9523,7 @@ var gameScreenIdentifierList2 = [
9525
9523
  }
9526
9524
  ];
9527
9525
 
9528
- // node_modules/@timardex/cluemart-shared/dist/chunk-QBU7N4P2.mjs
9526
+ // node_modules/@timardex/cluemart-shared/dist/chunk-A7IXLYYS.mjs
9529
9527
  var import_dayjs4 = __toESM(require("dayjs"), 1);
9530
9528
  var statusOptions2 = [
9531
9529
  ...Object.values(EnumInviteStatus2).map((status) => ({
@@ -10756,13 +10754,19 @@ async function findAffiliatesWithActiveVendorReferrals() {
10756
10754
  deletedAt: null
10757
10755
  }).select("_id affiliateCode affiliateResources owner").lean().exec();
10758
10756
  }
10759
- async function findEligibleReferredVendor(resourceId, affiliateCode) {
10760
- return await VendorModel.findOne({
10757
+ async function isEligibleReferredVendor({
10758
+ affiliateCode,
10759
+ resourceId,
10760
+ resourceOwnerUserId
10761
+ }) {
10762
+ const match = await VendorModel.exists({
10761
10763
  _id: resourceId,
10762
10764
  active: true,
10763
10765
  deletedAt: null,
10766
+ "owner.userId": resourceOwnerUserId,
10764
10767
  promoCodes: affiliateCode
10765
- }).select("_id name owner.userId").lean().exec();
10768
+ }).exec();
10769
+ return Boolean(match);
10766
10770
  }
10767
10771
  async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
10768
10772
  const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
@@ -10804,8 +10808,7 @@ async function tryAwardSubscriptionReward({
10804
10808
  createdAt,
10805
10809
  period,
10806
10810
  resource,
10807
- rewardType,
10808
- vendor
10811
+ rewardType
10809
10812
  }) {
10810
10813
  const reward = createAffiliateReward(rewardType, createdAt);
10811
10814
  const updateResult = await AffiliateModel.updateOne(
@@ -10815,7 +10818,7 @@ async function tryAwardSubscriptionReward({
10815
10818
  $elemMatch: {
10816
10819
  resourceActive: true,
10817
10820
  resourceDeletedAt: null,
10818
- resourceId: vendor._id,
10821
+ resourceId: resource.resourceId,
10819
10822
  resourceType: EnumResourceType.VENDOR,
10820
10823
  rewards: {
10821
10824
  $not: {
@@ -10840,15 +10843,12 @@ async function tryAwardSubscriptionReward({
10840
10843
  if (updateResult.modifiedCount === 0) {
10841
10844
  return "skipped";
10842
10845
  }
10843
- const affiliateOwnerUserId = affiliate.owner?.userId;
10844
- if (affiliateOwnerUserId) {
10845
- await notifyAffiliateOwnerOfSubscriptionReward({
10846
- affiliateId: affiliate._id,
10847
- affiliateOwnerUserId,
10848
- resourceName: resource.resourceName || vendor.name || "vendor",
10849
- rewardValue: reward.rewardValue
10850
- });
10851
- }
10846
+ await notifyAffiliateOwnerOfSubscriptionReward({
10847
+ affiliateId: affiliate._id,
10848
+ affiliateOwnerUserId: affiliate.owner.userId,
10849
+ resourceName: resource.resourceName,
10850
+ rewardValue: reward.rewardValue
10851
+ });
10852
10852
  return "awarded";
10853
10853
  }
10854
10854
  async function processAffiliateVendorReferral({
@@ -10859,15 +10859,16 @@ async function processAffiliateVendorReferral({
10859
10859
  period,
10860
10860
  resource
10861
10861
  }) {
10862
- const vendor = await findEligibleReferredVendor(
10863
- resource.resourceId,
10864
- affiliateCode
10865
- );
10866
- if (!vendor?.owner?.userId) {
10862
+ const vendorEligible = await isEligibleReferredVendor({
10863
+ affiliateCode,
10864
+ resourceId: resource.resourceId,
10865
+ resourceOwnerUserId: resource.resourceOwner.userId
10866
+ });
10867
+ if (!vendorEligible) {
10867
10868
  return "skipped";
10868
10869
  }
10869
10870
  const rewardType = await resolveSubscriptionRewardTypeForVendorOwner(
10870
- vendor.owner.userId,
10871
+ resource.resourceOwner.userId,
10871
10872
  now
10872
10873
  );
10873
10874
  if (!rewardType) {
@@ -10878,8 +10879,7 @@ async function processAffiliateVendorReferral({
10878
10879
  createdAt,
10879
10880
  period,
10880
10881
  resource,
10881
- rewardType,
10882
- vendor
10882
+ rewardType
10883
10883
  });
10884
10884
  }
10885
10885
  async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new Date()) {