@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.
- package/dist/{Affiliate-BxNv9k41.d.mts → Affiliate-B76iZ3fE.d.mts} +2 -1
- package/dist/{Affiliate-DRuifOv4.d.ts → Affiliate-gqV1-654.d.ts} +2 -1
- package/dist/{chunk-7X5A335O.mjs → chunk-SY7T26IW.mjs} +1 -1
- package/dist/{chunk-7X5A335O.mjs.map → chunk-SY7T26IW.mjs.map} +1 -1
- package/dist/index.cjs +25 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +25 -23
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +2 -2
- package/dist/mongoose/index.d.ts +2 -2
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +25 -23
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +4 -3
- package/dist/service/index.d.ts +4 -3
- package/dist/service/index.mjs +26 -24
- package/dist/service/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -724,8 +724,9 @@ declare const SchoolModel: mongoose__default.Model<SchoolDocument, {}, {}, {}, m
|
|
|
724
724
|
}, any>;
|
|
725
725
|
|
|
726
726
|
type SchemaAffiliateReward = AffiliateRewardType;
|
|
727
|
-
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId"> & {
|
|
727
|
+
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId" | "resourceOwner"> & {
|
|
728
728
|
resourceId: ObjectId;
|
|
729
|
+
resourceOwner: SchemaOwnerType;
|
|
729
730
|
};
|
|
730
731
|
type AffiliateDocument = Omit<AffiliateType, "_id" | "owner" | "affiliateResources"> & {
|
|
731
732
|
affiliateResources: SchemaAffiliateResourceType[];
|
|
@@ -761,8 +762,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
761
762
|
* Eligibility per affiliate resource:
|
|
762
763
|
* - Affiliate is not soft-deleted
|
|
763
764
|
* - Linked `affiliateResources` entry is vendor, `resourceActive`, and not deleted
|
|
764
|
-
* - Vendor is active, not deleted,
|
|
765
|
-
*
|
|
765
|
+
* - Vendor is active, not deleted, has the affiliate promo code, and
|
|
766
|
+
* `owner.userId` matches `affiliateResources.resourceOwner.userId`
|
|
767
|
+
* - `affiliateResources.resourceOwner` has a non-expired Standard / Pro / Pro+ vendor licence
|
|
766
768
|
*
|
|
767
769
|
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
768
770
|
* - Pro / Pro+ with paying Stripe (ACTIVE/TRIALING) → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
package/dist/index.d.ts
CHANGED
|
@@ -724,8 +724,9 @@ declare const SchoolModel: mongoose__default.Model<SchoolDocument, {}, {}, {}, m
|
|
|
724
724
|
}, any>;
|
|
725
725
|
|
|
726
726
|
type SchemaAffiliateReward = AffiliateRewardType;
|
|
727
|
-
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId"> & {
|
|
727
|
+
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId" | "resourceOwner"> & {
|
|
728
728
|
resourceId: ObjectId;
|
|
729
|
+
resourceOwner: SchemaOwnerType;
|
|
729
730
|
};
|
|
730
731
|
type AffiliateDocument = Omit<AffiliateType, "_id" | "owner" | "affiliateResources"> & {
|
|
731
732
|
affiliateResources: SchemaAffiliateResourceType[];
|
|
@@ -761,8 +762,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
761
762
|
* Eligibility per affiliate resource:
|
|
762
763
|
* - Affiliate is not soft-deleted
|
|
763
764
|
* - Linked `affiliateResources` entry is vendor, `resourceActive`, and not deleted
|
|
764
|
-
* - Vendor is active, not deleted,
|
|
765
|
-
*
|
|
765
|
+
* - Vendor is active, not deleted, has the affiliate promo code, and
|
|
766
|
+
* `owner.userId` matches `affiliateResources.resourceOwner.userId`
|
|
767
|
+
* - `affiliateResources.resourceOwner` has a non-expired Standard / Pro / Pro+ vendor licence
|
|
766
768
|
*
|
|
767
769
|
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
768
770
|
* - Pro / Pro+ with paying Stripe (ACTIVE/TRIALING) → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
package/dist/index.mjs
CHANGED
|
@@ -10656,13 +10656,19 @@ async function findAffiliatesWithActiveVendorReferrals() {
|
|
|
10656
10656
|
deletedAt: null
|
|
10657
10657
|
}).select("_id affiliateCode affiliateResources owner").lean().exec();
|
|
10658
10658
|
}
|
|
10659
|
-
async function
|
|
10660
|
-
|
|
10659
|
+
async function isEligibleReferredVendor({
|
|
10660
|
+
affiliateCode,
|
|
10661
|
+
resourceId,
|
|
10662
|
+
resourceOwnerUserId
|
|
10663
|
+
}) {
|
|
10664
|
+
const match = await VendorModel.exists({
|
|
10661
10665
|
_id: resourceId,
|
|
10662
10666
|
active: true,
|
|
10663
10667
|
deletedAt: null,
|
|
10668
|
+
"owner.userId": resourceOwnerUserId,
|
|
10664
10669
|
promoCodes: affiliateCode
|
|
10665
|
-
}).
|
|
10670
|
+
}).exec();
|
|
10671
|
+
return Boolean(match);
|
|
10666
10672
|
}
|
|
10667
10673
|
async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
|
|
10668
10674
|
const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
|
|
@@ -10704,8 +10710,7 @@ async function tryAwardSubscriptionReward({
|
|
|
10704
10710
|
createdAt,
|
|
10705
10711
|
period,
|
|
10706
10712
|
resource,
|
|
10707
|
-
rewardType
|
|
10708
|
-
vendor
|
|
10713
|
+
rewardType
|
|
10709
10714
|
}) {
|
|
10710
10715
|
const reward = createAffiliateReward(rewardType, createdAt);
|
|
10711
10716
|
const updateResult = await AffiliateModel.updateOne(
|
|
@@ -10715,7 +10720,7 @@ async function tryAwardSubscriptionReward({
|
|
|
10715
10720
|
$elemMatch: {
|
|
10716
10721
|
resourceActive: true,
|
|
10717
10722
|
resourceDeletedAt: null,
|
|
10718
|
-
resourceId:
|
|
10723
|
+
resourceId: resource.resourceId,
|
|
10719
10724
|
resourceType: EnumResourceType.VENDOR,
|
|
10720
10725
|
rewards: {
|
|
10721
10726
|
$not: {
|
|
@@ -10740,15 +10745,12 @@ async function tryAwardSubscriptionReward({
|
|
|
10740
10745
|
if (updateResult.modifiedCount === 0) {
|
|
10741
10746
|
return "skipped";
|
|
10742
10747
|
}
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
rewardValue: reward.rewardValue
|
|
10750
|
-
});
|
|
10751
|
-
}
|
|
10748
|
+
await notifyAffiliateOwnerOfSubscriptionReward({
|
|
10749
|
+
affiliateId: affiliate._id,
|
|
10750
|
+
affiliateOwnerUserId: affiliate.owner.userId,
|
|
10751
|
+
resourceName: resource.resourceName,
|
|
10752
|
+
rewardValue: reward.rewardValue
|
|
10753
|
+
});
|
|
10752
10754
|
return "awarded";
|
|
10753
10755
|
}
|
|
10754
10756
|
async function processAffiliateVendorReferral({
|
|
@@ -10759,15 +10761,16 @@ async function processAffiliateVendorReferral({
|
|
|
10759
10761
|
period,
|
|
10760
10762
|
resource
|
|
10761
10763
|
}) {
|
|
10762
|
-
const
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10764
|
+
const vendorEligible = await isEligibleReferredVendor({
|
|
10765
|
+
affiliateCode,
|
|
10766
|
+
resourceId: resource.resourceId,
|
|
10767
|
+
resourceOwnerUserId: resource.resourceOwner.userId
|
|
10768
|
+
});
|
|
10769
|
+
if (!vendorEligible) {
|
|
10767
10770
|
return "skipped";
|
|
10768
10771
|
}
|
|
10769
10772
|
const rewardType = await resolveSubscriptionRewardTypeForVendorOwner(
|
|
10770
|
-
|
|
10773
|
+
resource.resourceOwner.userId,
|
|
10771
10774
|
now
|
|
10772
10775
|
);
|
|
10773
10776
|
if (!rewardType) {
|
|
@@ -10778,8 +10781,7 @@ async function processAffiliateVendorReferral({
|
|
|
10778
10781
|
createdAt,
|
|
10779
10782
|
period,
|
|
10780
10783
|
resource,
|
|
10781
|
-
rewardType
|
|
10782
|
-
vendor
|
|
10784
|
+
rewardType
|
|
10783
10785
|
});
|
|
10784
10786
|
}
|
|
10785
10787
|
async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new Date()) {
|