@timardex/cluemart-server-shared 1.0.304 → 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-GQWLGM2W.mjs → chunk-SY7T26IW.mjs} +11 -1
- package/dist/chunk-SY7T26IW.mjs.map +1 -0
- package/dist/index.cjs +37 -25
- 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 +37 -25
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +10 -0
- 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 +37 -25
- 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 +28 -26
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-GQWLGM2W.mjs.map +0 -1
package/dist/service/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
3
|
import { PromoCodeType, UserLicenceType, UserType, EnumAffiliateRewardType, EnumUserLicence, DateTimeType, EventListItemType, DateTimeWithPriceType } from '@timardex/cluemart-shared';
|
|
4
|
-
import { n as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType } from '../Affiliate-
|
|
4
|
+
import { n as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType } from '../Affiliate-B76iZ3fE.mjs';
|
|
5
5
|
import { G as GraphQLContext, O as ObjectId, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.mjs';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
@@ -28,8 +28,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
28
28
|
* Eligibility per affiliate resource:
|
|
29
29
|
* - Affiliate is not soft-deleted
|
|
30
30
|
* - Linked `affiliateResources` entry is vendor, `resourceActive`, and not deleted
|
|
31
|
-
* - Vendor is active, not deleted,
|
|
32
|
-
*
|
|
31
|
+
* - Vendor is active, not deleted, has the affiliate promo code, and
|
|
32
|
+
* `owner.userId` matches `affiliateResources.resourceOwner.userId`
|
|
33
|
+
* - `affiliateResources.resourceOwner` has a non-expired Standard / Pro / Pro+ vendor licence
|
|
33
34
|
*
|
|
34
35
|
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
35
36
|
* - Pro / Pro+ with paying Stripe (ACTIVE/TRIALING) → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
package/dist/service/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
3
|
import { PromoCodeType, UserLicenceType, UserType, EnumAffiliateRewardType, EnumUserLicence, DateTimeType, EventListItemType, DateTimeWithPriceType } from '@timardex/cluemart-shared';
|
|
4
|
-
import { n as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType } from '../Affiliate-
|
|
4
|
+
import { n as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType } from '../Affiliate-gqV1-654.js';
|
|
5
5
|
import { G as GraphQLContext, O as ObjectId, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.js';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
@@ -28,8 +28,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
28
28
|
* Eligibility per affiliate resource:
|
|
29
29
|
* - Affiliate is not soft-deleted
|
|
30
30
|
* - Linked `affiliateResources` entry is vendor, `resourceActive`, and not deleted
|
|
31
|
-
* - Vendor is active, not deleted,
|
|
32
|
-
*
|
|
31
|
+
* - Vendor is active, not deleted, has the affiliate promo code, and
|
|
32
|
+
* `owner.userId` matches `affiliateResources.resourceOwner.userId`
|
|
33
|
+
* - `affiliateResources.resourceOwner` has a non-expired Standard / Pro / Pro+ vendor licence
|
|
33
34
|
*
|
|
34
35
|
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
35
36
|
* - Pro / Pro+ with paying Stripe (ACTIVE/TRIALING) → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
package/dist/service/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
VendorModel,
|
|
23
23
|
dateFormat,
|
|
24
24
|
timeFormat
|
|
25
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-SY7T26IW.mjs";
|
|
26
26
|
import "../chunk-6PNG5BI5.mjs";
|
|
27
27
|
|
|
28
28
|
// src/service/promoCode/constants.ts
|
|
@@ -95,7 +95,7 @@ var SHARE_RESOURCE_LABEL = {
|
|
|
95
95
|
school: "School"
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
// node_modules/@timardex/cluemart-shared/dist/chunk-
|
|
98
|
+
// node_modules/@timardex/cluemart-shared/dist/chunk-OBZTGPBJ.mjs
|
|
99
99
|
var PROMO_CODE_PREFIX = "CM-";
|
|
100
100
|
var OBJECT_ID_PATH_SEGMENT = "[a-f0-9]{24}";
|
|
101
101
|
var OBJECT_ID_PATH_SEGMENT_END = `${OBJECT_ID_PATH_SEGMENT}$`;
|
|
@@ -197,7 +197,7 @@ var gameScreenIdentifierList = [
|
|
|
197
197
|
}
|
|
198
198
|
];
|
|
199
199
|
|
|
200
|
-
// node_modules/@timardex/cluemart-shared/dist/chunk-
|
|
200
|
+
// node_modules/@timardex/cluemart-shared/dist/chunk-QBU7N4P2.mjs
|
|
201
201
|
import dayjs2 from "dayjs";
|
|
202
202
|
var statusOptions = [
|
|
203
203
|
...Object.values(EnumInviteStatus2).map((status) => ({
|
|
@@ -1428,13 +1428,19 @@ async function findAffiliatesWithActiveVendorReferrals() {
|
|
|
1428
1428
|
deletedAt: null
|
|
1429
1429
|
}).select("_id affiliateCode affiliateResources owner").lean().exec();
|
|
1430
1430
|
}
|
|
1431
|
-
async function
|
|
1432
|
-
|
|
1431
|
+
async function isEligibleReferredVendor({
|
|
1432
|
+
affiliateCode,
|
|
1433
|
+
resourceId,
|
|
1434
|
+
resourceOwnerUserId
|
|
1435
|
+
}) {
|
|
1436
|
+
const match = await VendorModel.exists({
|
|
1433
1437
|
_id: resourceId,
|
|
1434
1438
|
active: true,
|
|
1435
1439
|
deletedAt: null,
|
|
1440
|
+
"owner.userId": resourceOwnerUserId,
|
|
1436
1441
|
promoCodes: affiliateCode
|
|
1437
|
-
}).
|
|
1442
|
+
}).exec();
|
|
1443
|
+
return Boolean(match);
|
|
1438
1444
|
}
|
|
1439
1445
|
async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
|
|
1440
1446
|
const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
|
|
@@ -1476,8 +1482,7 @@ async function tryAwardSubscriptionReward({
|
|
|
1476
1482
|
createdAt,
|
|
1477
1483
|
period,
|
|
1478
1484
|
resource,
|
|
1479
|
-
rewardType
|
|
1480
|
-
vendor
|
|
1485
|
+
rewardType
|
|
1481
1486
|
}) {
|
|
1482
1487
|
const reward = createAffiliateReward(rewardType, createdAt);
|
|
1483
1488
|
const updateResult = await AffiliateModel.updateOne(
|
|
@@ -1487,7 +1492,7 @@ async function tryAwardSubscriptionReward({
|
|
|
1487
1492
|
$elemMatch: {
|
|
1488
1493
|
resourceActive: true,
|
|
1489
1494
|
resourceDeletedAt: null,
|
|
1490
|
-
resourceId:
|
|
1495
|
+
resourceId: resource.resourceId,
|
|
1491
1496
|
resourceType: EnumResourceType.VENDOR,
|
|
1492
1497
|
rewards: {
|
|
1493
1498
|
$not: {
|
|
@@ -1512,15 +1517,12 @@ async function tryAwardSubscriptionReward({
|
|
|
1512
1517
|
if (updateResult.modifiedCount === 0) {
|
|
1513
1518
|
return "skipped";
|
|
1514
1519
|
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
rewardValue: reward.rewardValue
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1520
|
+
await notifyAffiliateOwnerOfSubscriptionReward({
|
|
1521
|
+
affiliateId: affiliate._id,
|
|
1522
|
+
affiliateOwnerUserId: affiliate.owner.userId,
|
|
1523
|
+
resourceName: resource.resourceName,
|
|
1524
|
+
rewardValue: reward.rewardValue
|
|
1525
|
+
});
|
|
1524
1526
|
return "awarded";
|
|
1525
1527
|
}
|
|
1526
1528
|
async function processAffiliateVendorReferral({
|
|
@@ -1531,15 +1533,16 @@ async function processAffiliateVendorReferral({
|
|
|
1531
1533
|
period,
|
|
1532
1534
|
resource
|
|
1533
1535
|
}) {
|
|
1534
|
-
const
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1536
|
+
const vendorEligible = await isEligibleReferredVendor({
|
|
1537
|
+
affiliateCode,
|
|
1538
|
+
resourceId: resource.resourceId,
|
|
1539
|
+
resourceOwnerUserId: resource.resourceOwner.userId
|
|
1540
|
+
});
|
|
1541
|
+
if (!vendorEligible) {
|
|
1539
1542
|
return "skipped";
|
|
1540
1543
|
}
|
|
1541
1544
|
const rewardType = await resolveSubscriptionRewardTypeForVendorOwner(
|
|
1542
|
-
|
|
1545
|
+
resource.resourceOwner.userId,
|
|
1543
1546
|
now
|
|
1544
1547
|
);
|
|
1545
1548
|
if (!rewardType) {
|
|
@@ -1550,8 +1553,7 @@ async function processAffiliateVendorReferral({
|
|
|
1550
1553
|
createdAt,
|
|
1551
1554
|
period,
|
|
1552
1555
|
resource,
|
|
1553
|
-
rewardType
|
|
1554
|
-
vendor
|
|
1556
|
+
rewardType
|
|
1555
1557
|
});
|
|
1556
1558
|
}
|
|
1557
1559
|
async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new Date()) {
|