@timardex/cluemart-server-shared 1.0.305 → 1.0.306

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.
@@ -3,8 +3,8 @@ import { AdType, ReportChatUser, GoogleImportedMarket, PushTokenType, ResourceAc
3
3
  import mongoose__default from 'mongoose';
4
4
  import { O as ObjectId } from '../Chat-Wn7yfc3v.mjs';
5
5
  export { C as ChatModel, N as NotificationModel, a as SchemaChatMessageReactionType, S as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, e as SchemaChatType, f as SchemaCreateBulkNotificationInput, g as SchemaNotificationType, d as SchemaParticipantType } from '../Chat-Wn7yfc3v.mjs';
6
- import { S as SchemaOwnerType } from '../Affiliate-BxNv9k41.mjs';
7
- export { A as AffiliateModel, C as CategorySchema, c as ContactDetailsSchema, O as OwnerTypeSchema, k as RelationModel, j as RelationTypeSchema, R as ResourceImageTypeSchema, n as SchemaAffiliateResourceType, m as SchemaAffiliateReward, a as SchemaRelatedPostType, i as SchemaRelationType, b as SocialMediaTypeSchema, g as baseResourceFields, d as dateTimeSchema, l as locationGeoSchema, e as locationsSchema, f as relatedPostSchema, h as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-BxNv9k41.mjs';
6
+ import { S as SchemaOwnerType } from '../Affiliate-B76iZ3fE.mjs';
7
+ export { A as AffiliateModel, C as CategorySchema, c as ContactDetailsSchema, O as OwnerTypeSchema, k as RelationModel, j as RelationTypeSchema, R as ResourceImageTypeSchema, n as SchemaAffiliateResourceType, m as SchemaAffiliateReward, a as SchemaRelatedPostType, i as SchemaRelationType, b as SocialMediaTypeSchema, g as baseResourceFields, d as dateTimeSchema, l as locationGeoSchema, e as locationsSchema, f as relatedPostSchema, h as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-B76iZ3fE.mjs';
8
8
  import '@timardex/cluemart-shared/types';
9
9
  import 'express';
10
10
 
@@ -3,8 +3,8 @@ import { AdType, ReportChatUser, GoogleImportedMarket, PushTokenType, ResourceAc
3
3
  import mongoose__default from 'mongoose';
4
4
  import { O as ObjectId } from '../Chat-Wn7yfc3v.js';
5
5
  export { C as ChatModel, N as NotificationModel, a as SchemaChatMessageReactionType, S as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, e as SchemaChatType, f as SchemaCreateBulkNotificationInput, g as SchemaNotificationType, d as SchemaParticipantType } from '../Chat-Wn7yfc3v.js';
6
- import { S as SchemaOwnerType } from '../Affiliate-DRuifOv4.js';
7
- export { A as AffiliateModel, C as CategorySchema, c as ContactDetailsSchema, O as OwnerTypeSchema, k as RelationModel, j as RelationTypeSchema, R as ResourceImageTypeSchema, n as SchemaAffiliateResourceType, m as SchemaAffiliateReward, a as SchemaRelatedPostType, i as SchemaRelationType, b as SocialMediaTypeSchema, g as baseResourceFields, d as dateTimeSchema, l as locationGeoSchema, e as locationsSchema, f as relatedPostSchema, h as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-DRuifOv4.js';
6
+ import { S as SchemaOwnerType } from '../Affiliate-gqV1-654.js';
7
+ export { A as AffiliateModel, C as CategorySchema, c as ContactDetailsSchema, O as OwnerTypeSchema, k as RelationModel, j as RelationTypeSchema, R as ResourceImageTypeSchema, n as SchemaAffiliateResourceType, m as SchemaAffiliateReward, a as SchemaRelatedPostType, i as SchemaRelationType, b as SocialMediaTypeSchema, g as baseResourceFields, d as dateTimeSchema, l as locationGeoSchema, e as locationsSchema, f as relatedPostSchema, h as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-gqV1-654.js';
8
8
  import '@timardex/cluemart-shared/types';
9
9
  import 'express';
10
10
 
@@ -39,7 +39,7 @@ import {
39
39
  socialShareResourceSchema,
40
40
  termsAgreementSchema,
41
41
  userLicenseSchema
42
- } from "../chunk-7X5A335O.mjs";
42
+ } from "../chunk-SY7T26IW.mjs";
43
43
  export {
44
44
  APP_SETTINGS_ID,
45
45
  AdModel,
@@ -10713,13 +10713,19 @@ async function findAffiliatesWithActiveVendorReferrals() {
10713
10713
  deletedAt: null
10714
10714
  }).select("_id affiliateCode affiliateResources owner").lean().exec();
10715
10715
  }
10716
- async function findEligibleReferredVendor(resourceId, affiliateCode) {
10717
- return await VendorModel.findOne({
10716
+ async function isEligibleReferredVendor({
10717
+ affiliateCode,
10718
+ resourceId,
10719
+ resourceOwnerUserId
10720
+ }) {
10721
+ const match = await VendorModel.exists({
10718
10722
  _id: resourceId,
10719
10723
  active: true,
10720
10724
  deletedAt: null,
10725
+ "owner.userId": resourceOwnerUserId,
10721
10726
  promoCodes: affiliateCode
10722
- }).select("_id name owner.userId").lean().exec();
10727
+ }).exec();
10728
+ return Boolean(match);
10723
10729
  }
10724
10730
  async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
10725
10731
  const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
@@ -10761,8 +10767,7 @@ async function tryAwardSubscriptionReward({
10761
10767
  createdAt,
10762
10768
  period,
10763
10769
  resource,
10764
- rewardType,
10765
- vendor
10770
+ rewardType
10766
10771
  }) {
10767
10772
  const reward = createAffiliateReward(rewardType, createdAt);
10768
10773
  const updateResult = await AffiliateModel.updateOne(
@@ -10772,7 +10777,7 @@ async function tryAwardSubscriptionReward({
10772
10777
  $elemMatch: {
10773
10778
  resourceActive: true,
10774
10779
  resourceDeletedAt: null,
10775
- resourceId: vendor._id,
10780
+ resourceId: resource.resourceId,
10776
10781
  resourceType: EnumResourceType.VENDOR,
10777
10782
  rewards: {
10778
10783
  $not: {
@@ -10797,15 +10802,12 @@ async function tryAwardSubscriptionReward({
10797
10802
  if (updateResult.modifiedCount === 0) {
10798
10803
  return "skipped";
10799
10804
  }
10800
- const affiliateOwnerUserId = affiliate.owner?.userId;
10801
- if (affiliateOwnerUserId) {
10802
- await notifyAffiliateOwnerOfSubscriptionReward({
10803
- affiliateId: affiliate._id,
10804
- affiliateOwnerUserId,
10805
- resourceName: resource.resourceName || vendor.name || "vendor",
10806
- rewardValue: reward.rewardValue
10807
- });
10808
- }
10805
+ await notifyAffiliateOwnerOfSubscriptionReward({
10806
+ affiliateId: affiliate._id,
10807
+ affiliateOwnerUserId: affiliate.owner.userId,
10808
+ resourceName: resource.resourceName,
10809
+ rewardValue: reward.rewardValue
10810
+ });
10809
10811
  return "awarded";
10810
10812
  }
10811
10813
  async function processAffiliateVendorReferral({
@@ -10816,15 +10818,16 @@ async function processAffiliateVendorReferral({
10816
10818
  period,
10817
10819
  resource
10818
10820
  }) {
10819
- const vendor = await findEligibleReferredVendor(
10820
- resource.resourceId,
10821
- affiliateCode
10822
- );
10823
- if (!vendor?.owner?.userId) {
10821
+ const vendorEligible = await isEligibleReferredVendor({
10822
+ affiliateCode,
10823
+ resourceId: resource.resourceId,
10824
+ resourceOwnerUserId: resource.resourceOwner.userId
10825
+ });
10826
+ if (!vendorEligible) {
10824
10827
  return "skipped";
10825
10828
  }
10826
10829
  const rewardType = await resolveSubscriptionRewardTypeForVendorOwner(
10827
- vendor.owner.userId,
10830
+ resource.resourceOwner.userId,
10828
10831
  now
10829
10832
  );
10830
10833
  if (!rewardType) {
@@ -10835,8 +10838,7 @@ async function processAffiliateVendorReferral({
10835
10838
  createdAt,
10836
10839
  period,
10837
10840
  resource,
10838
- rewardType,
10839
- vendor
10841
+ rewardType
10840
10842
  });
10841
10843
  }
10842
10844
  async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new Date()) {