@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.
@@ -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-MTFOFVHB.mjs";
43
43
  export {
44
44
  APP_SETTINGS_ID,
45
45
  AdModel,
@@ -7372,7 +7372,6 @@ var AFFILIATE_DETAILS_FIELDS_FRAGMENT = gql`
7372
7372
  location {
7373
7373
  ...LocationFields
7374
7374
  }
7375
- region
7376
7375
  socialMedia {
7377
7376
  ...SocialMediaFields
7378
7377
  }
@@ -9257,7 +9256,6 @@ var affiliateDetailsSchema = new MongooseSchema25(
9257
9256
  required: true,
9258
9257
  type: String
9259
9258
  },
9260
- region: { required: true, type: String },
9261
9259
  socialMedia: { required: false, type: [SocialMediaTypeSchema] },
9262
9260
  termsAgreement: { required: true, type: termsAgreementSchema }
9263
9261
  },
@@ -9380,7 +9378,7 @@ var SHARE_RESOURCE_LABEL2 = {
9380
9378
  school: "School"
9381
9379
  };
9382
9380
 
9383
- // node_modules/@timardex/cluemart-shared/dist/chunk-OBZTGPBJ.mjs
9381
+ // node_modules/@timardex/cluemart-shared/dist/chunk-QMJB5OJ4.mjs
9384
9382
  var PROMO_CODE_PREFIX2 = "CM-";
9385
9383
  var OBJECT_ID_PATH_SEGMENT2 = "[a-f0-9]{24}";
9386
9384
  var OBJECT_ID_PATH_SEGMENT_END2 = `${OBJECT_ID_PATH_SEGMENT2}$`;
@@ -9482,7 +9480,7 @@ var gameScreenIdentifierList2 = [
9482
9480
  }
9483
9481
  ];
9484
9482
 
9485
- // node_modules/@timardex/cluemart-shared/dist/chunk-QBU7N4P2.mjs
9483
+ // node_modules/@timardex/cluemart-shared/dist/chunk-A7IXLYYS.mjs
9486
9484
  var import_dayjs4 = __toESM(require("dayjs"), 1);
9487
9485
  var statusOptions2 = [
9488
9486
  ...Object.values(EnumInviteStatus2).map((status) => ({
@@ -10713,13 +10711,19 @@ async function findAffiliatesWithActiveVendorReferrals() {
10713
10711
  deletedAt: null
10714
10712
  }).select("_id affiliateCode affiliateResources owner").lean().exec();
10715
10713
  }
10716
- async function findEligibleReferredVendor(resourceId, affiliateCode) {
10717
- return await VendorModel.findOne({
10714
+ async function isEligibleReferredVendor({
10715
+ affiliateCode,
10716
+ resourceId,
10717
+ resourceOwnerUserId
10718
+ }) {
10719
+ const match = await VendorModel.exists({
10718
10720
  _id: resourceId,
10719
10721
  active: true,
10720
10722
  deletedAt: null,
10723
+ "owner.userId": resourceOwnerUserId,
10721
10724
  promoCodes: affiliateCode
10722
- }).select("_id name owner.userId").lean().exec();
10725
+ }).exec();
10726
+ return Boolean(match);
10723
10727
  }
10724
10728
  async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
10725
10729
  const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
@@ -10761,8 +10765,7 @@ async function tryAwardSubscriptionReward({
10761
10765
  createdAt,
10762
10766
  period,
10763
10767
  resource,
10764
- rewardType,
10765
- vendor
10768
+ rewardType
10766
10769
  }) {
10767
10770
  const reward = createAffiliateReward(rewardType, createdAt);
10768
10771
  const updateResult = await AffiliateModel.updateOne(
@@ -10772,7 +10775,7 @@ async function tryAwardSubscriptionReward({
10772
10775
  $elemMatch: {
10773
10776
  resourceActive: true,
10774
10777
  resourceDeletedAt: null,
10775
- resourceId: vendor._id,
10778
+ resourceId: resource.resourceId,
10776
10779
  resourceType: EnumResourceType.VENDOR,
10777
10780
  rewards: {
10778
10781
  $not: {
@@ -10797,15 +10800,12 @@ async function tryAwardSubscriptionReward({
10797
10800
  if (updateResult.modifiedCount === 0) {
10798
10801
  return "skipped";
10799
10802
  }
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
- }
10803
+ await notifyAffiliateOwnerOfSubscriptionReward({
10804
+ affiliateId: affiliate._id,
10805
+ affiliateOwnerUserId: affiliate.owner.userId,
10806
+ resourceName: resource.resourceName,
10807
+ rewardValue: reward.rewardValue
10808
+ });
10809
10809
  return "awarded";
10810
10810
  }
10811
10811
  async function processAffiliateVendorReferral({
@@ -10816,15 +10816,16 @@ async function processAffiliateVendorReferral({
10816
10816
  period,
10817
10817
  resource
10818
10818
  }) {
10819
- const vendor = await findEligibleReferredVendor(
10820
- resource.resourceId,
10821
- affiliateCode
10822
- );
10823
- if (!vendor?.owner?.userId) {
10819
+ const vendorEligible = await isEligibleReferredVendor({
10820
+ affiliateCode,
10821
+ resourceId: resource.resourceId,
10822
+ resourceOwnerUserId: resource.resourceOwner.userId
10823
+ });
10824
+ if (!vendorEligible) {
10824
10825
  return "skipped";
10825
10826
  }
10826
10827
  const rewardType = await resolveSubscriptionRewardTypeForVendorOwner(
10827
- vendor.owner.userId,
10828
+ resource.resourceOwner.userId,
10828
10829
  now
10829
10830
  );
10830
10831
  if (!rewardType) {
@@ -10835,8 +10836,7 @@ async function processAffiliateVendorReferral({
10835
10836
  createdAt,
10836
10837
  period,
10837
10838
  resource,
10838
- rewardType,
10839
- vendor
10839
+ rewardType
10840
10840
  });
10841
10841
  }
10842
10842
  async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new Date()) {