@timardex/cluemart-server-shared 2.2.0 → 2.2.2
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-i11rkfv5.d.mts → Affiliate-6AEy-gNx.d.mts} +1 -1
- package/dist/{Affiliate-BSF7Wm6O.d.ts → Affiliate-D40kRxO_.d.ts} +1 -1
- package/dist/{chunk-HLRUWJLN.mjs → chunk-TIGQ6F5T.mjs} +75 -9
- package/dist/chunk-TIGQ6F5T.mjs.map +1 -0
- package/dist/{chunk-6PNG5BI5.mjs → chunk-TMPPPLIW.mjs} +1 -1
- package/dist/chunk-TMPPPLIW.mjs.map +1 -0
- package/dist/{index-Bq-lT7a2.d.mts → index-CmtBYjpi.d.mts} +4 -0
- package/dist/{index-Bq-lT7a2.d.ts → index-CmtBYjpi.d.ts} +4 -0
- package/dist/index.cjs +212 -212
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +40 -14
- package/dist/index.d.ts +40 -14
- package/dist/index.mjs +111 -114
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +75 -7
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +36 -6
- package/dist/mongoose/index.d.ts +36 -6
- package/dist/mongoose/index.mjs +5 -1
- package/dist/service/index.cjs +207 -211
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +7 -15
- package/dist/service/index.d.ts +7 -15
- package/dist/service/index.mjs +23 -92
- package/dist/service/index.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-6PNG5BI5.mjs.map +0 -1
- package/dist/chunk-HLRUWJLN.mjs.map +0 -1
package/dist/service/index.cjs
CHANGED
|
@@ -91,7 +91,7 @@ __export(service_exports, {
|
|
|
91
91
|
updateAdStatuses: () => updateAdStatuses,
|
|
92
92
|
updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
|
|
93
93
|
updateRelationDatesToUnavailable: () => updateRelationDatesToUnavailable,
|
|
94
|
-
updateSingleDateTimeStatus: () => updateSingleDateTimeStatus,
|
|
94
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared35.updateSingleDateTimeStatus,
|
|
95
95
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
96
96
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence
|
|
97
97
|
});
|
|
@@ -1118,16 +1118,24 @@ var GoogleImportedMarketModel = import_mongoose10.default.models.GoogleImportedM
|
|
|
1118
1118
|
var import_cluemart_shared9 = require("@timardex/cluemart-shared");
|
|
1119
1119
|
var import_mongoose11 = __toESM(require("mongoose"));
|
|
1120
1120
|
var MongooseSchema7 = import_mongoose11.default.Schema;
|
|
1121
|
+
var notificationDataSchema = new MongooseSchema7(
|
|
1122
|
+
{
|
|
1123
|
+
resourceId: { required: true, type: String },
|
|
1124
|
+
resourceName: { required: true, type: String },
|
|
1125
|
+
resourceType: {
|
|
1126
|
+
enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
|
|
1127
|
+
required: true,
|
|
1128
|
+
type: String
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
{ _id: false }
|
|
1132
|
+
);
|
|
1121
1133
|
var schema8 = new MongooseSchema7(
|
|
1122
1134
|
{
|
|
1123
1135
|
data: {
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
|
|
1128
|
-
required: true,
|
|
1129
|
-
type: String
|
|
1130
|
-
}
|
|
1136
|
+
default: null,
|
|
1137
|
+
required: false,
|
|
1138
|
+
type: notificationDataSchema
|
|
1131
1139
|
},
|
|
1132
1140
|
isRead: { default: false, index: true, required: true, type: Boolean },
|
|
1133
1141
|
message: { required: true, type: String },
|
|
@@ -2507,6 +2515,62 @@ schema24.index({ active: 1, deletedAt: 1, "owner.userId": 1 });
|
|
|
2507
2515
|
schema24.index({ "couponData.participantUsers.userId": 1 });
|
|
2508
2516
|
var CouponModel = import_mongoose32.default.models.Coupon || import_mongoose32.default.model("Coupon", schema24);
|
|
2509
2517
|
|
|
2518
|
+
// src/mongoose/Impersonation.ts
|
|
2519
|
+
var import_cluemart_shared22 = require("@timardex/cluemart-shared");
|
|
2520
|
+
var import_mongoose33 = __toESM(require("mongoose"));
|
|
2521
|
+
var MongooseSchema28 = import_mongoose33.default.Schema;
|
|
2522
|
+
var impersonationSessionSchema = new MongooseSchema28(
|
|
2523
|
+
{
|
|
2524
|
+
expiresAt: { expires: 0, required: true, type: Date },
|
|
2525
|
+
impersonatedUserId: {
|
|
2526
|
+
index: true,
|
|
2527
|
+
ref: "User",
|
|
2528
|
+
required: true,
|
|
2529
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2530
|
+
},
|
|
2531
|
+
impersonatorUserId: {
|
|
2532
|
+
index: true,
|
|
2533
|
+
ref: "User",
|
|
2534
|
+
required: true,
|
|
2535
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2536
|
+
},
|
|
2537
|
+
refreshToken: { required: true, type: String }
|
|
2538
|
+
},
|
|
2539
|
+
{ timestamps: true }
|
|
2540
|
+
);
|
|
2541
|
+
var ImpersonationSessionModel = import_mongoose33.default.models.ImpersonationSession || import_mongoose33.default.model(
|
|
2542
|
+
"ImpersonationSession",
|
|
2543
|
+
impersonationSessionSchema
|
|
2544
|
+
);
|
|
2545
|
+
var impersonationAuditSchema = new MongooseSchema28(
|
|
2546
|
+
{
|
|
2547
|
+
action: { enum: ["start", "end"], required: true, type: String },
|
|
2548
|
+
endReason: { type: String },
|
|
2549
|
+
impersonatedUserId: {
|
|
2550
|
+
ref: "User",
|
|
2551
|
+
required: true,
|
|
2552
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2553
|
+
},
|
|
2554
|
+
impersonatorUserId: {
|
|
2555
|
+
ref: "User",
|
|
2556
|
+
required: true,
|
|
2557
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2558
|
+
},
|
|
2559
|
+
resourceId: { type: import_mongoose33.default.Schema.Types.ObjectId },
|
|
2560
|
+
resourceType: { enum: Object.values(import_cluemart_shared22.EnumResourceType), type: String },
|
|
2561
|
+
sessionId: {
|
|
2562
|
+
ref: "ImpersonationSession",
|
|
2563
|
+
required: true,
|
|
2564
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2565
|
+
}
|
|
2566
|
+
},
|
|
2567
|
+
{ timestamps: true }
|
|
2568
|
+
);
|
|
2569
|
+
var ImpersonationAuditModel = import_mongoose33.default.models.ImpersonationAudit || import_mongoose33.default.model(
|
|
2570
|
+
"ImpersonationAudit",
|
|
2571
|
+
impersonationAuditSchema
|
|
2572
|
+
);
|
|
2573
|
+
|
|
2510
2574
|
// src/service/promoCode/constants.ts
|
|
2511
2575
|
var ACTIVE_NOT_DELETED_FILTER = {
|
|
2512
2576
|
active: true,
|
|
@@ -2523,31 +2587,30 @@ async function activeAffiliateCodeExists(affiliateCode) {
|
|
|
2523
2587
|
}
|
|
2524
2588
|
|
|
2525
2589
|
// src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
|
|
2526
|
-
var
|
|
2590
|
+
var import_cluemart_shared24 = require("@timardex/cluemart-shared");
|
|
2527
2591
|
var import_utils3 = require("@timardex/cluemart-shared/utils");
|
|
2528
2592
|
|
|
2529
2593
|
// src/service/saveNotificationsInDb.ts
|
|
2530
2594
|
async function saveNotificationsInDb(payload) {
|
|
2531
2595
|
const { data, message, title, type, userIds } = payload;
|
|
2532
|
-
|
|
2596
|
+
const notifications = userIds.map((userId) => ({
|
|
2597
|
+
data,
|
|
2598
|
+
isRead: false,
|
|
2599
|
+
message,
|
|
2600
|
+
title,
|
|
2601
|
+
type,
|
|
2602
|
+
userId
|
|
2603
|
+
}));
|
|
2533
2604
|
try {
|
|
2534
|
-
const notifications = userIds.map((userId) => ({
|
|
2535
|
-
data,
|
|
2536
|
-
isRead: false,
|
|
2537
|
-
message,
|
|
2538
|
-
title,
|
|
2539
|
-
type,
|
|
2540
|
-
userId
|
|
2541
|
-
}));
|
|
2542
2605
|
await NotificationModel.insertMany(notifications);
|
|
2543
|
-
console.log(
|
|
2544
|
-
`Created ${notifications.length} notifications for ${userIds.length} users`
|
|
2545
|
-
);
|
|
2546
|
-
return [...new Set(userIds)];
|
|
2547
2606
|
} catch (error) {
|
|
2548
2607
|
console.error("Failed to create notifications:", error);
|
|
2549
|
-
|
|
2608
|
+
throw error;
|
|
2550
2609
|
}
|
|
2610
|
+
console.log(
|
|
2611
|
+
`Created ${notifications.length} notifications for ${userIds.length} users`
|
|
2612
|
+
);
|
|
2613
|
+
return [...new Set(userIds)];
|
|
2551
2614
|
}
|
|
2552
2615
|
|
|
2553
2616
|
// src/service/sendPushNotifications.ts
|
|
@@ -2571,7 +2634,7 @@ function createPushMessages({
|
|
|
2571
2634
|
}
|
|
2572
2635
|
messages.push({
|
|
2573
2636
|
body: message,
|
|
2574
|
-
data: { ...data },
|
|
2637
|
+
...data ? { data: { ...data } } : {},
|
|
2575
2638
|
sound: "tui.wav",
|
|
2576
2639
|
title,
|
|
2577
2640
|
to: token
|
|
@@ -2626,7 +2689,6 @@ async function sendPushNotifications({
|
|
|
2626
2689
|
}) {
|
|
2627
2690
|
const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
|
|
2628
2691
|
const expoTokens = pushTokens.map((token) => token.token);
|
|
2629
|
-
if (!data) return;
|
|
2630
2692
|
const { messages, invalidTokens } = createPushMessages({
|
|
2631
2693
|
data,
|
|
2632
2694
|
message,
|
|
@@ -2660,7 +2722,7 @@ async function sendPushNotifications({
|
|
|
2660
2722
|
}
|
|
2661
2723
|
|
|
2662
2724
|
// src/service/affiliate/vendorSubscriptionRewards.ts
|
|
2663
|
-
var
|
|
2725
|
+
var import_cluemart_shared23 = require("@timardex/cluemart-shared");
|
|
2664
2726
|
var import_dayjs = __toESM(require("dayjs"));
|
|
2665
2727
|
var import_timezone = __toESM(require("dayjs/plugin/timezone"));
|
|
2666
2728
|
var import_utc = __toESM(require("dayjs/plugin/utc"));
|
|
@@ -2718,14 +2780,14 @@ import_dayjs.default.extend(import_timezone.default);
|
|
|
2718
2780
|
var SUBSCRIPTION_REWARD_TIMEZONE = "Pacific/Auckland";
|
|
2719
2781
|
async function mapVendorLicenceToSubscriptionRewardType(userId, now = /* @__PURE__ */ new Date()) {
|
|
2720
2782
|
const { hasSubscription, validTypes } = await getPayingVendorStripeSubscriptionPlan(userId, now);
|
|
2721
|
-
if (validTypes.has(
|
|
2783
|
+
if (validTypes.has(import_cluemart_shared23.EnumUserLicence.PRO_VENDOR) || validTypes.has(import_cluemart_shared23.EnumUserLicence.PRO_PLUS_VENDOR)) {
|
|
2722
2784
|
if (hasSubscription) {
|
|
2723
|
-
return
|
|
2785
|
+
return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
|
|
2724
2786
|
}
|
|
2725
|
-
return
|
|
2787
|
+
return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
|
|
2726
2788
|
}
|
|
2727
|
-
if (validTypes.has(
|
|
2728
|
-
return
|
|
2789
|
+
if (validTypes.has(import_cluemart_shared23.EnumUserLicence.STANDARD_VENDOR)) {
|
|
2790
|
+
return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
|
|
2729
2791
|
}
|
|
2730
2792
|
return null;
|
|
2731
2793
|
}
|
|
@@ -2737,7 +2799,7 @@ function getSubscriptionRewardPeriodBounds(now = /* @__PURE__ */ new Date()) {
|
|
|
2737
2799
|
|
|
2738
2800
|
// src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
|
|
2739
2801
|
function isEligibleVendorResource(resource) {
|
|
2740
|
-
return resource.resourceType ===
|
|
2802
|
+
return resource.resourceType === import_cluemart_shared24.EnumResourceType.VENDOR && resource.resourceActive === true && resource.resourceDeletedAt == null;
|
|
2741
2803
|
}
|
|
2742
2804
|
async function findAffiliatesWithActiveVendorReferrals() {
|
|
2743
2805
|
return await AffiliateModel.find({
|
|
@@ -2746,7 +2808,7 @@ async function findAffiliatesWithActiveVendorReferrals() {
|
|
|
2746
2808
|
$elemMatch: {
|
|
2747
2809
|
resourceActive: true,
|
|
2748
2810
|
resourceDeletedAt: null,
|
|
2749
|
-
resourceType:
|
|
2811
|
+
resourceType: import_cluemart_shared24.EnumResourceType.VENDOR
|
|
2750
2812
|
}
|
|
2751
2813
|
},
|
|
2752
2814
|
deletedAt: null
|
|
@@ -2780,11 +2842,11 @@ async function notifyAffiliateOwnerOfSubscriptionReward({
|
|
|
2780
2842
|
data: {
|
|
2781
2843
|
resourceId: String(affiliateId),
|
|
2782
2844
|
resourceName: resourceNames.join(", "),
|
|
2783
|
-
resourceType:
|
|
2845
|
+
resourceType: import_cluemart_shared24.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
|
|
2784
2846
|
},
|
|
2785
2847
|
message,
|
|
2786
2848
|
title: "Affiliate points earned",
|
|
2787
|
-
type:
|
|
2849
|
+
type: import_cluemart_shared24.EnumNotificationType.SYSTEM,
|
|
2788
2850
|
userIds: [affiliateOwnerUserId]
|
|
2789
2851
|
};
|
|
2790
2852
|
try {
|
|
@@ -2813,7 +2875,7 @@ async function tryAwardSubscriptionReward({
|
|
|
2813
2875
|
resourceActive: true,
|
|
2814
2876
|
resourceDeletedAt: null,
|
|
2815
2877
|
resourceId: resource.resourceId,
|
|
2816
|
-
resourceType:
|
|
2878
|
+
resourceType: import_cluemart_shared24.EnumResourceType.VENDOR,
|
|
2817
2879
|
rewards: {
|
|
2818
2880
|
$not: {
|
|
2819
2881
|
$elemMatch: {
|
|
@@ -2934,7 +2996,7 @@ function normalizeAffiliatePromoCodes(promoCodes) {
|
|
|
2934
2996
|
}
|
|
2935
2997
|
|
|
2936
2998
|
// src/service/database.ts
|
|
2937
|
-
var
|
|
2999
|
+
var import_mongoose37 = __toESM(require("mongoose"));
|
|
2938
3000
|
var connectToDatabase = async ({
|
|
2939
3001
|
appName,
|
|
2940
3002
|
dbName,
|
|
@@ -2947,7 +3009,7 @@ var connectToDatabase = async ({
|
|
|
2947
3009
|
// Fallback to MongoDB Atlas connection string
|
|
2948
3010
|
`mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
|
|
2949
3011
|
);
|
|
2950
|
-
await
|
|
3012
|
+
await import_mongoose37.default.connect(mongoUri);
|
|
2951
3013
|
const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
|
|
2952
3014
|
console.log(
|
|
2953
3015
|
`${connectionType} connected from server/src/service/database.ts`
|
|
@@ -2960,7 +3022,7 @@ var connectToDatabase = async ({
|
|
|
2960
3022
|
|
|
2961
3023
|
// src/types/index.ts
|
|
2962
3024
|
var import_express = __toESM(require("express"));
|
|
2963
|
-
var
|
|
3025
|
+
var import_mongoose38 = __toESM(require("mongoose"));
|
|
2964
3026
|
|
|
2965
3027
|
// src/service/notifyUsers.ts
|
|
2966
3028
|
async function publishNotificationEvents(userId, pubsub) {
|
|
@@ -3008,7 +3070,7 @@ async function notifyUsers({
|
|
|
3008
3070
|
}
|
|
3009
3071
|
|
|
3010
3072
|
// src/service/updateAdStatus.ts
|
|
3011
|
-
var
|
|
3073
|
+
var import_cluemart_shared25 = require("@timardex/cluemart-shared");
|
|
3012
3074
|
async function updateAdStatuses() {
|
|
3013
3075
|
const now = /* @__PURE__ */ new Date();
|
|
3014
3076
|
const invalidResult = await AdModel.updateMany(
|
|
@@ -3018,50 +3080,50 @@ async function updateAdStatuses() {
|
|
|
3018
3080
|
{ end: { $exists: false } },
|
|
3019
3081
|
{ $expr: { $gt: ["$start", "$end"] } }
|
|
3020
3082
|
],
|
|
3021
|
-
status: { $ne:
|
|
3083
|
+
status: { $ne: import_cluemart_shared25.EnumAdStatus.PAUSED }
|
|
3022
3084
|
},
|
|
3023
|
-
{ $set: { status:
|
|
3085
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
|
|
3024
3086
|
);
|
|
3025
3087
|
const expiredResult = await AdModel.updateMany(
|
|
3026
|
-
{ end: { $lte: now }, status: { $ne:
|
|
3027
|
-
{ $set: { status:
|
|
3088
|
+
{ end: { $lte: now }, status: { $ne: import_cluemart_shared25.EnumAdStatus.EXPIRED } },
|
|
3089
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.EXPIRED } }
|
|
3028
3090
|
);
|
|
3029
3091
|
const eligibleBooking = {
|
|
3030
3092
|
$or: [
|
|
3031
3093
|
{ bookingKind: { $exists: false } },
|
|
3032
3094
|
{ bookingKind: null },
|
|
3033
3095
|
{
|
|
3034
|
-
approvalStatus:
|
|
3035
|
-
bookingKind:
|
|
3096
|
+
approvalStatus: import_cluemart_shared25.EnumAdApprovalStatus.APPROVED,
|
|
3097
|
+
bookingKind: import_cluemart_shared25.EnumAdBookingSlotKind.RESERVED
|
|
3036
3098
|
},
|
|
3037
3099
|
{
|
|
3038
|
-
approvalStatus:
|
|
3039
|
-
bookingKind:
|
|
3040
|
-
paymentStatus:
|
|
3100
|
+
approvalStatus: import_cluemart_shared25.EnumAdApprovalStatus.APPROVED,
|
|
3101
|
+
bookingKind: import_cluemart_shared25.EnumAdBookingSlotKind.PAID,
|
|
3102
|
+
paymentStatus: import_cluemart_shared25.EnumAdPaymentStatus.PAID
|
|
3041
3103
|
}
|
|
3042
3104
|
]
|
|
3043
3105
|
};
|
|
3044
3106
|
const awaitingApprovalResult = await AdModel.updateMany(
|
|
3045
3107
|
{
|
|
3046
3108
|
$nor: eligibleBooking.$or,
|
|
3047
|
-
bookingKind: { $in: Object.values(
|
|
3109
|
+
bookingKind: { $in: Object.values(import_cluemart_shared25.EnumAdBookingSlotKind) },
|
|
3048
3110
|
end: { $gt: now },
|
|
3049
|
-
status:
|
|
3111
|
+
status: import_cluemart_shared25.EnumAdStatus.ACTIVE
|
|
3050
3112
|
},
|
|
3051
|
-
{ $set: { status:
|
|
3113
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
|
|
3052
3114
|
);
|
|
3053
3115
|
const activeResult = await AdModel.updateMany(
|
|
3054
3116
|
{
|
|
3055
3117
|
end: { $gt: now },
|
|
3056
3118
|
start: { $lte: now },
|
|
3057
|
-
status: { $ne:
|
|
3119
|
+
status: { $ne: import_cluemart_shared25.EnumAdStatus.ACTIVE },
|
|
3058
3120
|
...eligibleBooking
|
|
3059
3121
|
},
|
|
3060
|
-
{ $set: { status:
|
|
3122
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.ACTIVE } }
|
|
3061
3123
|
);
|
|
3062
3124
|
const pausedResult = await AdModel.updateMany(
|
|
3063
|
-
{ start: { $gt: now }, status: { $ne:
|
|
3064
|
-
{ $set: { status:
|
|
3125
|
+
{ start: { $gt: now }, status: { $ne: import_cluemart_shared25.EnumAdStatus.PAUSED } },
|
|
3126
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
|
|
3065
3127
|
);
|
|
3066
3128
|
console.log(
|
|
3067
3129
|
`\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
|
|
@@ -3069,15 +3131,15 @@ async function updateAdStatuses() {
|
|
|
3069
3131
|
}
|
|
3070
3132
|
|
|
3071
3133
|
// src/service/objectIdToString.ts
|
|
3072
|
-
var
|
|
3134
|
+
var import_mongoose40 = __toESM(require("mongoose"));
|
|
3073
3135
|
function isValidObjectId(value) {
|
|
3074
|
-
return
|
|
3136
|
+
return import_mongoose40.default.Types.ObjectId.isValid(value);
|
|
3075
3137
|
}
|
|
3076
3138
|
function convertObjectIdsToStrings(obj) {
|
|
3077
3139
|
if (obj === null || obj === void 0) {
|
|
3078
3140
|
return obj;
|
|
3079
3141
|
}
|
|
3080
|
-
if (obj instanceof
|
|
3142
|
+
if (obj instanceof import_mongoose40.default.Types.ObjectId) {
|
|
3081
3143
|
return obj.toString();
|
|
3082
3144
|
}
|
|
3083
3145
|
if (obj instanceof Date) {
|
|
@@ -3097,18 +3159,16 @@ function convertObjectIdsToStrings(obj) {
|
|
|
3097
3159
|
}
|
|
3098
3160
|
|
|
3099
3161
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3100
|
-
var
|
|
3162
|
+
var import_cluemart_shared27 = require("@timardex/cluemart-shared");
|
|
3101
3163
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
3102
|
-
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3103
|
-
var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
|
|
3104
3164
|
|
|
3105
3165
|
// src/service/event/archiveEndedEventDates.ts
|
|
3106
|
-
var
|
|
3166
|
+
var import_cluemart_shared26 = require("@timardex/cluemart-shared");
|
|
3107
3167
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3108
|
-
|
|
3168
|
+
import_cluemart_shared26.EnumEventDateStatus.ENDED
|
|
3109
3169
|
]);
|
|
3110
3170
|
var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
|
|
3111
|
-
|
|
3171
|
+
import_cluemart_shared26.EnumEventDateStatus.INVALID
|
|
3112
3172
|
]);
|
|
3113
3173
|
function splitEventDatesForArchive(dateTime) {
|
|
3114
3174
|
return {
|
|
@@ -3143,73 +3203,6 @@ async function persistArchivedEventDates(eventId, slots) {
|
|
|
3143
3203
|
}
|
|
3144
3204
|
|
|
3145
3205
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3146
|
-
import_dayjs2.default.extend(import_customParseFormat.default);
|
|
3147
|
-
import_dayjs2.default.extend(import_isoWeek.default);
|
|
3148
|
-
var MANUAL_DATE_STATUSES = /* @__PURE__ */ new Set([
|
|
3149
|
-
import_cluemart_shared26.EnumEventDateStatus.CANCELED,
|
|
3150
|
-
import_cluemart_shared26.EnumEventDateStatus.RE_SCHEDULED
|
|
3151
|
-
]);
|
|
3152
|
-
function getFutureEventStatus(startDateTime, now) {
|
|
3153
|
-
const hoursUntilStart = startDateTime.diff(now, "hour", true);
|
|
3154
|
-
if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
|
|
3155
|
-
return import_cluemart_shared26.EnumEventDateStatus.STARTING_SOON;
|
|
3156
|
-
}
|
|
3157
|
-
if (startDateTime.isSame(now, "day")) {
|
|
3158
|
-
return import_cluemart_shared26.EnumEventDateStatus.TODAY;
|
|
3159
|
-
}
|
|
3160
|
-
if (startDateTime.isSame(now.add(1, "day"), "day")) {
|
|
3161
|
-
return import_cluemart_shared26.EnumEventDateStatus.TOMORROW;
|
|
3162
|
-
}
|
|
3163
|
-
if (startDateTime.isSame(now, "isoWeek")) {
|
|
3164
|
-
return import_cluemart_shared26.EnumEventDateStatus.THIS_WEEK;
|
|
3165
|
-
}
|
|
3166
|
-
if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
|
|
3167
|
-
return import_cluemart_shared26.EnumEventDateStatus.NEXT_WEEK;
|
|
3168
|
-
}
|
|
3169
|
-
return import_cluemart_shared26.EnumEventDateStatus.UPCOMING;
|
|
3170
|
-
}
|
|
3171
|
-
function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
|
|
3172
|
-
if (MANUAL_DATE_STATUSES.has(dateTime.dateStatus)) {
|
|
3173
|
-
return dateTime;
|
|
3174
|
-
}
|
|
3175
|
-
const dateTimeFormat = `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`;
|
|
3176
|
-
const startDateTime = (0, import_dayjs2.default)(
|
|
3177
|
-
`${dateTime.startDate} ${dateTime.startTime}`,
|
|
3178
|
-
dateTimeFormat,
|
|
3179
|
-
true
|
|
3180
|
-
);
|
|
3181
|
-
const endDateTime = (0, import_dayjs2.default)(
|
|
3182
|
-
`${dateTime.endDate} ${dateTime.endTime}`,
|
|
3183
|
-
dateTimeFormat,
|
|
3184
|
-
true
|
|
3185
|
-
);
|
|
3186
|
-
if (!startDateTime.isValid() || !endDateTime.isValid()) {
|
|
3187
|
-
return {
|
|
3188
|
-
...dateTime,
|
|
3189
|
-
dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
|
|
3190
|
-
};
|
|
3191
|
-
}
|
|
3192
|
-
if (endDateTime.isBefore(startDateTime)) {
|
|
3193
|
-
return {
|
|
3194
|
-
...dateTime,
|
|
3195
|
-
dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
|
|
3196
|
-
};
|
|
3197
|
-
}
|
|
3198
|
-
let dateStatus;
|
|
3199
|
-
if (endDateTime.isAfter(now)) {
|
|
3200
|
-
if (startDateTime.isAfter(now)) {
|
|
3201
|
-
dateStatus = getFutureEventStatus(startDateTime, now);
|
|
3202
|
-
} else {
|
|
3203
|
-
dateStatus = import_cluemart_shared26.EnumEventDateStatus.STARTED;
|
|
3204
|
-
}
|
|
3205
|
-
} else {
|
|
3206
|
-
dateStatus = import_cluemart_shared26.EnumEventDateStatus.ENDED;
|
|
3207
|
-
}
|
|
3208
|
-
return {
|
|
3209
|
-
...dateTime,
|
|
3210
|
-
dateStatus
|
|
3211
|
-
};
|
|
3212
|
-
}
|
|
3213
3206
|
var dateTimeStatusFilter = {
|
|
3214
3207
|
dateTime: { $ne: [], $type: "array" },
|
|
3215
3208
|
deletedAt: null
|
|
@@ -3238,7 +3231,7 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3238
3231
|
try {
|
|
3239
3232
|
for await (const doc of cursor) {
|
|
3240
3233
|
const dateTime = doc.dateTime.map(
|
|
3241
|
-
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
3234
|
+
(slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
|
|
3242
3235
|
);
|
|
3243
3236
|
if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
|
|
3244
3237
|
continue;
|
|
@@ -3261,7 +3254,7 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3261
3254
|
}
|
|
3262
3255
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
3263
3256
|
"dateTime.dateStatus": {
|
|
3264
|
-
$in: [
|
|
3257
|
+
$in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
|
|
3265
3258
|
},
|
|
3266
3259
|
deletedAt: null
|
|
3267
3260
|
};
|
|
@@ -3283,7 +3276,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3283
3276
|
try {
|
|
3284
3277
|
for await (const doc of cursor) {
|
|
3285
3278
|
const updated = doc.dateTime.map(
|
|
3286
|
-
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
3279
|
+
(slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
|
|
3287
3280
|
);
|
|
3288
3281
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3289
3282
|
if (archive.length === 0 && discard.length === 0) {
|
|
@@ -3307,7 +3300,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3307
3300
|
$pull: {
|
|
3308
3301
|
dateTime: {
|
|
3309
3302
|
dateStatus: {
|
|
3310
|
-
$in: [
|
|
3303
|
+
$in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
|
|
3311
3304
|
}
|
|
3312
3305
|
}
|
|
3313
3306
|
}
|
|
@@ -3341,9 +3334,9 @@ async function cleanEventInfoDates(now) {
|
|
|
3341
3334
|
try {
|
|
3342
3335
|
for await (const doc of cursor) {
|
|
3343
3336
|
const updated = doc.dateTime.map(
|
|
3344
|
-
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
3337
|
+
(slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
|
|
3345
3338
|
);
|
|
3346
|
-
const kept = (0,
|
|
3339
|
+
const kept = (0, import_cluemart_shared27.filterDatesByFutureStatus)(updated);
|
|
3347
3340
|
if (kept.length === updated.length) {
|
|
3348
3341
|
continue;
|
|
3349
3342
|
}
|
|
@@ -3388,6 +3381,9 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
3388
3381
|
}
|
|
3389
3382
|
}
|
|
3390
3383
|
|
|
3384
|
+
// src/service/index.ts
|
|
3385
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
3386
|
+
|
|
3391
3387
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
3392
3388
|
async function findEventOrImportedMarketById(resourceId) {
|
|
3393
3389
|
if (!resourceId) {
|
|
@@ -3402,7 +3398,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
3402
3398
|
}
|
|
3403
3399
|
|
|
3404
3400
|
// src/service/relations.ts
|
|
3405
|
-
var
|
|
3401
|
+
var import_cluemart_shared28 = require("@timardex/cluemart-shared");
|
|
3406
3402
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
3407
3403
|
if (!previousDateTime?.length) {
|
|
3408
3404
|
return false;
|
|
@@ -3420,7 +3416,7 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3420
3416
|
) ?? false;
|
|
3421
3417
|
return {
|
|
3422
3418
|
...relationDate,
|
|
3423
|
-
status: existsInEvent ? relationDate.status :
|
|
3419
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared28.EnumInviteStatus.UNAVAILABLE
|
|
3424
3420
|
};
|
|
3425
3421
|
});
|
|
3426
3422
|
}
|
|
@@ -3429,15 +3425,15 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3429
3425
|
var import_dayjs6 = __toESM(require("dayjs"));
|
|
3430
3426
|
|
|
3431
3427
|
// src/service/license/compliance/utils.ts
|
|
3432
|
-
var
|
|
3428
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
3433
3429
|
var import_dayjs5 = __toESM(require("dayjs"));
|
|
3434
3430
|
|
|
3435
3431
|
// src/service/license/compliance/event.ts
|
|
3436
|
-
var
|
|
3432
|
+
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
3437
3433
|
var eventLicences = [
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3434
|
+
import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT,
|
|
3435
|
+
import_cluemart_shared29.EnumUserLicence.PRO_EVENT,
|
|
3436
|
+
import_cluemart_shared29.EnumUserLicence.PRO_PLUS_EVENT
|
|
3441
3437
|
];
|
|
3442
3438
|
async function handleEventLicenceCompliance(user, now) {
|
|
3443
3439
|
if (!user.licences || !user.events?.length) {
|
|
@@ -3649,9 +3645,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
3649
3645
|
}
|
|
3650
3646
|
|
|
3651
3647
|
// src/service/license/compliance/partner.ts
|
|
3652
|
-
var
|
|
3648
|
+
var import_cluemart_shared30 = require("@timardex/cluemart-shared");
|
|
3653
3649
|
var partnerLicences = [
|
|
3654
|
-
|
|
3650
|
+
import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER
|
|
3655
3651
|
];
|
|
3656
3652
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
3657
3653
|
if (!user.licences || !user.partner) {
|
|
@@ -3661,11 +3657,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
3661
3657
|
}
|
|
3662
3658
|
|
|
3663
3659
|
// src/service/license/compliance/vendor.ts
|
|
3664
|
-
var
|
|
3660
|
+
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3665
3661
|
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3666
3662
|
|
|
3667
3663
|
// src/service/license/models.ts
|
|
3668
|
-
var
|
|
3664
|
+
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3669
3665
|
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3670
3666
|
var import_graphql = require("graphql");
|
|
3671
3667
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
@@ -3677,31 +3673,31 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
|
3677
3673
|
return LicenceCategory2;
|
|
3678
3674
|
})(LicenceCategory || {});
|
|
3679
3675
|
var licenceCategoryMapping = {
|
|
3680
|
-
[
|
|
3681
|
-
[
|
|
3682
|
-
[
|
|
3683
|
-
[
|
|
3684
|
-
[
|
|
3685
|
-
[
|
|
3686
|
-
[
|
|
3687
|
-
[
|
|
3688
|
-
[
|
|
3676
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
|
|
3677
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
|
|
3678
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
|
|
3679
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
|
|
3680
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
|
|
3681
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
|
|
3682
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
|
|
3683
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
3684
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
|
|
3689
3685
|
};
|
|
3690
3686
|
var licencePriority = {
|
|
3691
|
-
[
|
|
3692
|
-
[
|
|
3693
|
-
[
|
|
3694
|
-
[
|
|
3695
|
-
[
|
|
3696
|
-
[
|
|
3697
|
-
[
|
|
3698
|
-
[
|
|
3699
|
-
[
|
|
3687
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: 3,
|
|
3688
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: 2,
|
|
3689
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: 1,
|
|
3690
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
|
|
3691
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: 2,
|
|
3692
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: 1,
|
|
3693
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: 1,
|
|
3694
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: 1,
|
|
3695
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: 1
|
|
3700
3696
|
};
|
|
3701
3697
|
var standardLicences = [
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3698
|
+
import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
|
|
3699
|
+
import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
|
|
3700
|
+
import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER
|
|
3705
3701
|
];
|
|
3706
3702
|
var standardLicenceSet = new Set(standardLicences);
|
|
3707
3703
|
function isStandardLicence(licence) {
|
|
@@ -3715,11 +3711,11 @@ var categoryRegexMapping = {
|
|
|
3715
3711
|
["school" /* SCHOOL */]: /_school$/
|
|
3716
3712
|
};
|
|
3717
3713
|
var categoryFallbackLicence = {
|
|
3718
|
-
["event" /* EVENT */]:
|
|
3719
|
-
["partner" /* PARTNER */]:
|
|
3720
|
-
["vendor" /* VENDOR */]:
|
|
3721
|
-
["affiliate" /* AFFILIATE */]:
|
|
3722
|
-
["school" /* SCHOOL */]:
|
|
3714
|
+
["event" /* EVENT */]: import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
|
|
3715
|
+
["partner" /* PARTNER */]: import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER,
|
|
3716
|
+
["vendor" /* VENDOR */]: import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
|
|
3717
|
+
["affiliate" /* AFFILIATE */]: import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE,
|
|
3718
|
+
["school" /* SCHOOL */]: import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL
|
|
3723
3719
|
};
|
|
3724
3720
|
var LicenceFilterInput = {
|
|
3725
3721
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -3749,11 +3745,11 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
3749
3745
|
function createLicenceObject(expiryDate, licenceType) {
|
|
3750
3746
|
const today = (0, import_dayjs3.default)();
|
|
3751
3747
|
const expiryDateMapping = {
|
|
3752
|
-
[
|
|
3753
|
-
[
|
|
3754
|
-
[
|
|
3755
|
-
[
|
|
3756
|
-
[
|
|
3748
|
+
[import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
3749
|
+
[import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
3750
|
+
[import_cluemart_shared31.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
|
|
3751
|
+
[import_cluemart_shared31.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
|
|
3752
|
+
[import_cluemart_shared31.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
|
|
3757
3753
|
};
|
|
3758
3754
|
const licenceObject = {
|
|
3759
3755
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -3857,13 +3853,13 @@ async function checkOwnerHasLicence({
|
|
|
3857
3853
|
const owner = await UserModel.findById(userId);
|
|
3858
3854
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
3859
3855
|
const categoryByResource = {
|
|
3860
|
-
[
|
|
3861
|
-
[
|
|
3862
|
-
[
|
|
3863
|
-
[
|
|
3864
|
-
[
|
|
3856
|
+
[import_cluemart_shared31.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
3857
|
+
[import_cluemart_shared31.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
3858
|
+
[import_cluemart_shared31.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
|
|
3859
|
+
[import_cluemart_shared31.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
3860
|
+
[import_cluemart_shared31.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
|
|
3865
3861
|
};
|
|
3866
|
-
if (!(0,
|
|
3862
|
+
if (!(0, import_cluemart_shared31.isNonVisitorResourceType)(resourceType)) {
|
|
3867
3863
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
3868
3864
|
}
|
|
3869
3865
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -3943,7 +3939,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
3943
3939
|
return (result?.matchedCount ?? 0) > 0;
|
|
3944
3940
|
}
|
|
3945
3941
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
3946
|
-
const isStandardVendor = licenceType ===
|
|
3942
|
+
const isStandardVendor = licenceType === import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR;
|
|
3947
3943
|
if (!isStandardVendor) {
|
|
3948
3944
|
return;
|
|
3949
3945
|
}
|
|
@@ -3990,7 +3986,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
3990
3986
|
return (result?.matchedCount ?? 0) > 0;
|
|
3991
3987
|
}
|
|
3992
3988
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
3993
|
-
const isProVendor = licenceType ===
|
|
3989
|
+
const isProVendor = licenceType === import_cluemart_shared32.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared32.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
3994
3990
|
if (!isProVendor) {
|
|
3995
3991
|
return;
|
|
3996
3992
|
}
|
|
@@ -4011,14 +4007,14 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4011
4007
|
return false;
|
|
4012
4008
|
}
|
|
4013
4009
|
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs4.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4014
|
-
const hasActivePaymentGracePeriod = (stripe.status ===
|
|
4010
|
+
const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared32.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared32.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
4015
4011
|
if (hasActivePaymentGracePeriod) {
|
|
4016
4012
|
return true;
|
|
4017
4013
|
}
|
|
4018
4014
|
if (!stripe.subscriptionId) {
|
|
4019
4015
|
return false;
|
|
4020
4016
|
}
|
|
4021
|
-
if (stripe.status !==
|
|
4017
|
+
if (stripe.status !== import_cluemart_shared32.EnumSubscriptionStatus.ACTIVE) {
|
|
4022
4018
|
return false;
|
|
4023
4019
|
}
|
|
4024
4020
|
if (!stripe.endDate) {
|
|
@@ -4038,7 +4034,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4038
4034
|
return;
|
|
4039
4035
|
}
|
|
4040
4036
|
const proLicences = vendorLicencesOfUser.filter(
|
|
4041
|
-
(licence) => licence.licenceType !==
|
|
4037
|
+
(licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
|
|
4042
4038
|
);
|
|
4043
4039
|
const expiredProLicences = proLicences.filter(
|
|
4044
4040
|
(licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now)
|
|
@@ -4051,7 +4047,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4051
4047
|
const expiredProLicence = expiredProLicences.some(
|
|
4052
4048
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4053
4049
|
);
|
|
4054
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences,
|
|
4050
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
|
|
4055
4051
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4056
4052
|
(licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4057
4053
|
);
|
|
@@ -4067,7 +4063,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4067
4063
|
"owner.userId": user._id
|
|
4068
4064
|
}).lean().exec();
|
|
4069
4065
|
}
|
|
4070
|
-
const licencesToSync =
|
|
4066
|
+
const licencesToSync = import_cluemart_shared32.vendorLicences.filter(
|
|
4071
4067
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
4072
4068
|
);
|
|
4073
4069
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -4082,11 +4078,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4082
4078
|
data: {
|
|
4083
4079
|
resourceId: String(vendor._id),
|
|
4084
4080
|
resourceName: vendor.name,
|
|
4085
|
-
resourceType:
|
|
4081
|
+
resourceType: import_cluemart_shared32.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
4086
4082
|
},
|
|
4087
4083
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
4088
4084
|
title: `Vendor Licence Downgraded`,
|
|
4089
|
-
type:
|
|
4085
|
+
type: import_cluemart_shared32.EnumNotificationType.SYSTEM,
|
|
4090
4086
|
userIds: [user._id]
|
|
4091
4087
|
};
|
|
4092
4088
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -4119,7 +4115,7 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4119
4115
|
effectiveVendorLicences,
|
|
4120
4116
|
"vendor" /* VENDOR */
|
|
4121
4117
|
);
|
|
4122
|
-
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[
|
|
4118
|
+
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared32.EnumUserLicence.PRO_VENDOR];
|
|
4123
4119
|
}
|
|
4124
4120
|
|
|
4125
4121
|
// src/service/license/compliance/utils.ts
|
|
@@ -4129,12 +4125,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4129
4125
|
const pipeline = buildLicenceExpiryPipeline({
|
|
4130
4126
|
downgradeBranches: [
|
|
4131
4127
|
{
|
|
4132
|
-
case:
|
|
4133
|
-
then:
|
|
4128
|
+
case: import_cluemart_shared33.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
4129
|
+
then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
|
|
4134
4130
|
},
|
|
4135
4131
|
{
|
|
4136
|
-
case:
|
|
4137
|
-
then:
|
|
4132
|
+
case: import_cluemart_shared33.EnumUserLicence.PRO_VENDOR,
|
|
4133
|
+
then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
|
|
4138
4134
|
}
|
|
4139
4135
|
],
|
|
4140
4136
|
licenceTypes,
|
|
@@ -4263,7 +4259,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
|
4263
4259
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
4264
4260
|
|
|
4265
4261
|
// src/service/license/reminder/utils.ts
|
|
4266
|
-
var
|
|
4262
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4267
4263
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4268
4264
|
var import_dayjs7 = __toESM(require("dayjs"));
|
|
4269
4265
|
|
|
@@ -4329,28 +4325,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
|
4329
4325
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4330
4326
|
}
|
|
4331
4327
|
function getLicenseName(licenceType) {
|
|
4332
|
-
return
|
|
4328
|
+
return import_cluemart_shared34.licenseNiceNames[licenceType] || licenceType;
|
|
4333
4329
|
}
|
|
4334
4330
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
4335
4331
|
if (isVendorLicense) {
|
|
4336
4332
|
return {
|
|
4337
|
-
notificationType:
|
|
4338
|
-
resourceType:
|
|
4333
|
+
notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
|
|
4334
|
+
resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
4339
4335
|
};
|
|
4340
4336
|
}
|
|
4341
4337
|
if (isPartnerLicense) {
|
|
4342
4338
|
return {
|
|
4343
|
-
notificationType:
|
|
4344
|
-
resourceType:
|
|
4339
|
+
notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
|
|
4340
|
+
resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
4345
4341
|
};
|
|
4346
4342
|
}
|
|
4347
4343
|
return {
|
|
4348
|
-
notificationType:
|
|
4349
|
-
resourceType:
|
|
4344
|
+
notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
|
|
4345
|
+
resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
4350
4346
|
};
|
|
4351
4347
|
}
|
|
4352
4348
|
async function getLicenseResourceInfo(user, licence) {
|
|
4353
|
-
const isVendorLicense =
|
|
4349
|
+
const isVendorLicense = import_cluemart_shared34.vendorLicences.includes(licence.licenceType);
|
|
4354
4350
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
4355
4351
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4356
4352
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -4398,11 +4394,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
4398
4394
|
};
|
|
4399
4395
|
}
|
|
4400
4396
|
function getLicenceExpiryMode(licenceType) {
|
|
4401
|
-
return licenceType ===
|
|
4397
|
+
return licenceType === import_cluemart_shared34.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
4402
4398
|
}
|
|
4403
4399
|
async function sendLicenseReminder(user, licence) {
|
|
4404
4400
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4405
|
-
const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(
|
|
4401
|
+
const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
|
|
4406
4402
|
const userId = String(user._id);
|
|
4407
4403
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4408
4404
|
if (!resourceInfo) {
|