@timardex/cluemart-server-shared 4.0.8 → 4.2.0
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-CpoM9_Bb.d.mts → Affiliate-Bilg9mgw.d.mts} +43 -4
- package/dist/{Affiliate-YoKkDGxN.d.ts → Affiliate-CfG8ctIo.d.ts} +43 -4
- package/dist/{chunk-TSKI3WB2.mjs → chunk-ABW2L2HY.mjs} +81 -2
- package/dist/chunk-ABW2L2HY.mjs.map +1 -0
- package/dist/index.cjs +665 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +294 -10
- package/dist/index.d.ts +294 -10
- package/dist/index.mjs +558 -70
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +80 -1
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +57 -9
- package/dist/mongoose/index.d.ts +57 -9
- package/dist/mongoose/index.mjs +3 -1
- package/dist/service/index.cjs +662 -168
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +200 -3
- package/dist/service/index.d.ts +200 -3
- package/dist/service/index.mjs +477 -68
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-TSKI3WB2.mjs.map +0 -1
package/dist/service/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(service_exports, {
|
|
|
35
35
|
REMINDER_WINDOW_MAX_HOURS: () => REMINDER_WINDOW_MAX_HOURS,
|
|
36
36
|
REMINDER_WINDOW_MIN_HOURS: () => REMINDER_WINDOW_MIN_HOURS,
|
|
37
37
|
SUBSCRIPTION_REWARD_TIMEZONE: () => SUBSCRIPTION_REWARD_TIMEZONE,
|
|
38
|
+
acceptedAssociateUserIds: () => acceptedAssociateUserIds,
|
|
38
39
|
activeAffiliateCodeExists: () => activeAffiliateCodeExists,
|
|
39
40
|
awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
|
|
40
41
|
buildLicenceExpiryPipeline: () => buildLicenceExpiryPipeline,
|
|
@@ -48,6 +49,9 @@ __export(service_exports, {
|
|
|
48
49
|
convertObjectIdsToStrings: () => convertObjectIdsToStrings,
|
|
49
50
|
createLicenceObject: () => createLicenceObject,
|
|
50
51
|
dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
|
|
52
|
+
detachAssociateGrantsForResources: () => detachAssociateGrantsForResources,
|
|
53
|
+
detachStaleAssociateGrants: () => detachStaleAssociateGrants,
|
|
54
|
+
detachUsersFromResource: () => detachUsersFromResource,
|
|
51
55
|
didRemoveAnyEventDates: () => didRemoveAnyEventDates,
|
|
52
56
|
didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
|
|
53
57
|
downgradeVendorProFeatures: () => downgradeVendorProFeatures,
|
|
@@ -57,6 +61,8 @@ __export(service_exports, {
|
|
|
57
61
|
eventLicences: () => eventLicences,
|
|
58
62
|
findAffiliateByPromoCode: () => findAffiliateByPromoCode,
|
|
59
63
|
findEventOrImportedMarketById: () => findEventOrImportedMarketById,
|
|
64
|
+
getActiveLicenceForResource: () => getActiveLicenceForResource,
|
|
65
|
+
getAssociateAccessMeta: () => getAssociateAccessMeta,
|
|
60
66
|
getEventResourceInfo: () => getEventResourceInfo,
|
|
61
67
|
getHighestLicenceForCategory: () => getHighestLicenceForCategory,
|
|
62
68
|
getLicenceCategory: () => getLicenceCategory,
|
|
@@ -66,11 +72,17 @@ __export(service_exports, {
|
|
|
66
72
|
getPayingStripeSubscriptionPlan: () => getPayingStripeSubscriptionPlan,
|
|
67
73
|
getPayingVendorStripeSubscriptionPlan: () => getPayingVendorStripeSubscriptionPlan,
|
|
68
74
|
getSubscriptionRewardPeriodBounds: () => getSubscriptionRewardPeriodBounds,
|
|
75
|
+
getUserIdsWithActiveProLicence: () => getUserIdsWithActiveProLicence,
|
|
69
76
|
getVendorResourceInfo: () => getVendorResourceInfo,
|
|
77
|
+
grantAssociateGrants: () => grantAssociateGrants,
|
|
70
78
|
handleEventLicenceCompliance: () => handleEventLicenceCompliance,
|
|
71
79
|
handlePartnerLicenceCompliance: () => handlePartnerLicenceCompliance,
|
|
72
80
|
handleVendorLicenceCompliance: () => handleVendorLicenceCompliance,
|
|
81
|
+
hasActiveProLicenceForResource: () => hasActiveProLicenceForResource,
|
|
73
82
|
hasValidLicence: () => hasValidLicence,
|
|
83
|
+
isAssociableResourceType: () => isAssociableResourceType,
|
|
84
|
+
isProLicence: () => isProLicence,
|
|
85
|
+
isProtectedByCurrentStripeSubscription: () => isProtectedByCurrentStripeSubscription,
|
|
74
86
|
isStandardLicence: () => isStandardLicence,
|
|
75
87
|
isValidObjectId: () => isValidObjectId,
|
|
76
88
|
licenceCategoryMapping: () => licenceCategoryMapping,
|
|
@@ -85,6 +97,7 @@ __export(service_exports, {
|
|
|
85
97
|
processUserCompliance: () => processUserCompliance,
|
|
86
98
|
processUserLicenseReminders: () => processUserLicenseReminders,
|
|
87
99
|
publishNotificationEvents: () => publishNotificationEvents,
|
|
100
|
+
reconcileAssociateGrants: () => reconcileAssociateGrants,
|
|
88
101
|
remindUsersAboutLicenseExpiration: () => remindUsersAboutLicenseExpiration,
|
|
89
102
|
replaceUserLicenceWithObject: () => replaceUserLicenceWithObject,
|
|
90
103
|
restoreVendorProFeatures: () => restoreVendorProFeatures,
|
|
@@ -98,7 +111,7 @@ __export(service_exports, {
|
|
|
98
111
|
updateAdStatuses: () => updateAdStatuses,
|
|
99
112
|
updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
|
|
100
113
|
updateRelationDatesToCanceled: () => updateRelationDatesToCanceled,
|
|
101
|
-
updateSingleDateTimeStatus: () =>
|
|
114
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared39.updateSingleDateTimeStatus,
|
|
102
115
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
103
116
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence
|
|
104
117
|
});
|
|
@@ -766,6 +779,25 @@ var OwnerTypeSchema = new MongooseSchema5(
|
|
|
766
779
|
{ _id: false }
|
|
767
780
|
// Prevents Mongoose from creating an additional _id field for subdocuments
|
|
768
781
|
);
|
|
782
|
+
var AssociateTypeSchema = new MongooseSchema5(
|
|
783
|
+
{
|
|
784
|
+
addedAt: { default: Date.now, required: false, type: Date },
|
|
785
|
+
email: { lowercase: true, required: true, trim: true, type: String },
|
|
786
|
+
respondedAt: { default: null, required: false, type: Date },
|
|
787
|
+
status: {
|
|
788
|
+
default: import_cluemart_shared8.EnumAssociateStatus.PENDING,
|
|
789
|
+
enum: Object.values(import_cluemart_shared8.EnumAssociateStatus),
|
|
790
|
+
required: true,
|
|
791
|
+
type: String
|
|
792
|
+
},
|
|
793
|
+
userId: {
|
|
794
|
+
ref: "User",
|
|
795
|
+
required: true,
|
|
796
|
+
type: import_mongoose9.default.Schema.Types.ObjectId
|
|
797
|
+
}
|
|
798
|
+
},
|
|
799
|
+
{ _id: false }
|
|
800
|
+
);
|
|
769
801
|
var SocialMediaTypeSchema = new MongooseSchema5(
|
|
770
802
|
{
|
|
771
803
|
link: { required: true, type: String },
|
|
@@ -931,6 +963,7 @@ var baseResourceFields = {
|
|
|
931
963
|
type: [import_mongoose9.default.Schema.Types.ObjectId]
|
|
932
964
|
},
|
|
933
965
|
approvedAt: { default: null, required: false, type: Date },
|
|
966
|
+
associates: { default: [], required: false, type: [AssociateTypeSchema] },
|
|
934
967
|
contactDetails: { required: false, type: ContactDetailsSchema },
|
|
935
968
|
cover: {
|
|
936
969
|
required: true,
|
|
@@ -1197,6 +1230,8 @@ var schema8 = new MongooseSchema7(
|
|
|
1197
1230
|
missingFields: { required: false, type: [String] },
|
|
1198
1231
|
name: { required: true, type: String },
|
|
1199
1232
|
openingHours: { required: false, type: [String] },
|
|
1233
|
+
publicationCityUnknown: { default: false, required: false, type: Boolean },
|
|
1234
|
+
publicationKey: { required: false, type: String },
|
|
1200
1235
|
rainOrShine: { required: true, type: Boolean },
|
|
1201
1236
|
rating: { required: false, type: Number },
|
|
1202
1237
|
region: { required: false, type: String },
|
|
@@ -1208,6 +1243,7 @@ var schema8 = new MongooseSchema7(
|
|
|
1208
1243
|
required: false,
|
|
1209
1244
|
type: import_mongoose11.default.Schema.Types.ObjectId
|
|
1210
1245
|
},
|
|
1246
|
+
reviewerEditedAt: { default: null, required: false, type: Date },
|
|
1211
1247
|
reviewStatus: {
|
|
1212
1248
|
default: import_cluemart_shared10.EnumImportedMarketReviewStatus.PENDING,
|
|
1213
1249
|
enum: Object.values(import_cluemart_shared10.EnumImportedMarketReviewStatus),
|
|
@@ -1244,6 +1280,16 @@ schema8.index({
|
|
|
1244
1280
|
_id: 1
|
|
1245
1281
|
});
|
|
1246
1282
|
schema8.index({ region: 1, searchName: 1 });
|
|
1283
|
+
schema8.index(
|
|
1284
|
+
{ publicationKey: 1 },
|
|
1285
|
+
{
|
|
1286
|
+
name: "ai_market_publication_key",
|
|
1287
|
+
partialFilterExpression: {
|
|
1288
|
+
publicationKey: { $exists: true, $type: "string" }
|
|
1289
|
+
},
|
|
1290
|
+
unique: true
|
|
1291
|
+
}
|
|
1292
|
+
);
|
|
1247
1293
|
schema8.index({ slug: 1 });
|
|
1248
1294
|
schema8.index({ reviewStatus: 1 });
|
|
1249
1295
|
schema8.index({ description: "text", name: "text" });
|
|
@@ -1797,6 +1843,29 @@ var userOverallPointsSchema = new MongooseSchema16(
|
|
|
1797
1843
|
},
|
|
1798
1844
|
{ _id: false }
|
|
1799
1845
|
);
|
|
1846
|
+
var userAssociatedResourcesSchema = new MongooseSchema16(
|
|
1847
|
+
{
|
|
1848
|
+
events: {
|
|
1849
|
+
default: [],
|
|
1850
|
+
ref: "Event",
|
|
1851
|
+
required: false,
|
|
1852
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1853
|
+
},
|
|
1854
|
+
partners: {
|
|
1855
|
+
default: [],
|
|
1856
|
+
ref: "Partner",
|
|
1857
|
+
required: false,
|
|
1858
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1859
|
+
},
|
|
1860
|
+
vendors: {
|
|
1861
|
+
default: [],
|
|
1862
|
+
ref: "Vendor",
|
|
1863
|
+
required: false,
|
|
1864
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1865
|
+
}
|
|
1866
|
+
},
|
|
1867
|
+
{ _id: false }
|
|
1868
|
+
);
|
|
1800
1869
|
var schema15 = new MongooseSchema16(
|
|
1801
1870
|
{
|
|
1802
1871
|
active: { default: false, required: true, type: Boolean },
|
|
@@ -1805,6 +1874,11 @@ var schema15 = new MongooseSchema16(
|
|
|
1805
1874
|
required: false,
|
|
1806
1875
|
type: import_mongoose20.default.Schema.Types.ObjectId
|
|
1807
1876
|
},
|
|
1877
|
+
associatedResources: {
|
|
1878
|
+
default: () => ({ events: [], partners: [], vendors: [] }),
|
|
1879
|
+
required: false,
|
|
1880
|
+
type: userAssociatedResourcesSchema
|
|
1881
|
+
},
|
|
1808
1882
|
avatar: {
|
|
1809
1883
|
required: false,
|
|
1810
1884
|
type: ResourceImageTypeSchema
|
|
@@ -1815,7 +1889,10 @@ var schema15 = new MongooseSchema16(
|
|
|
1815
1889
|
type: import_mongoose20.default.Schema.Types.ObjectId
|
|
1816
1890
|
},
|
|
1817
1891
|
deletedAt: { default: null, required: false, type: Date },
|
|
1818
|
-
|
|
1892
|
+
// `normalizeEmail` (`cluemart-shared`) is trim + lower-case; keeping the same
|
|
1893
|
+
// rule here means every write path — resolvers, seeds, scripts — stores the
|
|
1894
|
+
// comparable form, not only the clients that validate through `emailRequiredSchema`.
|
|
1895
|
+
email: { lowercase: true, required: true, trim: true, type: String },
|
|
1819
1896
|
emailSentFor: {
|
|
1820
1897
|
enum: Object.values(import_cluemart_shared16.EnumNotificationResourceType),
|
|
1821
1898
|
required: false,
|
|
@@ -1930,6 +2007,9 @@ schema15.index({ "licences.expiryDate": 1 });
|
|
|
1930
2007
|
schema15.index({ "licences.licenceType": 1 });
|
|
1931
2008
|
schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
|
|
1932
2009
|
schema15.index({ email: "text", firstName: "text", lastName: "text" });
|
|
2010
|
+
schema15.index({ "associatedResources.events": 1 });
|
|
2011
|
+
schema15.index({ "associatedResources.partners": 1 });
|
|
2012
|
+
schema15.index({ "associatedResources.vendors": 1 });
|
|
1933
2013
|
var UserModel = import_mongoose20.default.models.User || import_mongoose20.default.model("User", schema15);
|
|
1934
2014
|
|
|
1935
2015
|
// src/mongoose/VerificationToken.ts
|
|
@@ -2063,6 +2143,7 @@ schema17.index({
|
|
|
2063
2143
|
name: "text"
|
|
2064
2144
|
});
|
|
2065
2145
|
schema17.index({ deletedAt: 1, "owner.userId": 1 });
|
|
2146
|
+
schema17.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2066
2147
|
schema17.plugin(searchNamePlugin);
|
|
2067
2148
|
var VendorModel = import_mongoose22.default.models.Vendor || import_mongoose22.default.model("Vendor", schema17);
|
|
2068
2149
|
|
|
@@ -2168,6 +2249,13 @@ var schema20 = new MongooseSchema21(
|
|
|
2168
2249
|
{
|
|
2169
2250
|
...baseResourceFields,
|
|
2170
2251
|
// Importing base resource fields from global.ts
|
|
2252
|
+
// Claim link of the AI-imported market this event was created from, the
|
|
2253
|
+
// counterpart of `googlePlaceId`. Written once by `createEvent`.
|
|
2254
|
+
aiImportedMarketSourceKey: {
|
|
2255
|
+
default: null,
|
|
2256
|
+
required: false,
|
|
2257
|
+
type: String
|
|
2258
|
+
},
|
|
2171
2259
|
claimed: { default: true, required: false, type: Boolean },
|
|
2172
2260
|
dateTime: { required: true, type: [dateTimeSchema] },
|
|
2173
2261
|
eventInfoId: {
|
|
@@ -2207,6 +2295,7 @@ schema20.index({ "dateTime.dateStatus": 1 });
|
|
|
2207
2295
|
schema20.index({ slug: 1 });
|
|
2208
2296
|
schema20.index({ description: "text", name: "text", tags: "text" });
|
|
2209
2297
|
schema20.index({ deletedAt: 1, "owner.userId": 1 });
|
|
2298
|
+
schema20.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2210
2299
|
schema20.plugin(searchNamePlugin);
|
|
2211
2300
|
var EventModel = import_mongoose25.default.models.Event || import_mongoose25.default.model("Event", schema20);
|
|
2212
2301
|
|
|
@@ -2253,6 +2342,7 @@ schema22.index({ "location.geo": "2dsphere" });
|
|
|
2253
2342
|
schema22.index({ slug: 1 });
|
|
2254
2343
|
schema22.index({ name: "text", description: "text" });
|
|
2255
2344
|
schema22.index({ "owner.userId": 1, deletedAt: 1 });
|
|
2345
|
+
schema22.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2256
2346
|
schema22.plugin(searchNamePlugin);
|
|
2257
2347
|
var PartnerModel = import_mongoose27.default.models.Partner || import_mongoose27.default.model("Partner", schema22);
|
|
2258
2348
|
|
|
@@ -3318,14 +3408,310 @@ function normalizeAffiliatePromoCodes(promoCodes) {
|
|
|
3318
3408
|
return [...new Set(normalized)];
|
|
3319
3409
|
}
|
|
3320
3410
|
|
|
3411
|
+
// src/service/associates/index.ts
|
|
3412
|
+
var import_cluemart_shared28 = require("@timardex/cluemart-shared");
|
|
3413
|
+
var import_mongoose42 = __toESM(require("mongoose"));
|
|
3414
|
+
function isAssociableResourceType(resourceType) {
|
|
3415
|
+
return resourceType === import_cluemart_shared28.EnumResourceType.EVENT || resourceType === import_cluemart_shared28.EnumResourceType.PARTNER || resourceType === import_cluemart_shared28.EnumResourceType.VENDOR;
|
|
3416
|
+
}
|
|
3417
|
+
function getAssociateAccessMeta(resourceType) {
|
|
3418
|
+
if (resourceType === import_cluemart_shared28.EnumResourceType.EVENT) {
|
|
3419
|
+
return {
|
|
3420
|
+
associatedField: "events",
|
|
3421
|
+
associatedPath: "associatedResources.events",
|
|
3422
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_EVENT
|
|
3423
|
+
};
|
|
3424
|
+
}
|
|
3425
|
+
if (resourceType === import_cluemart_shared28.EnumResourceType.PARTNER) {
|
|
3426
|
+
return {
|
|
3427
|
+
associatedField: "partners",
|
|
3428
|
+
associatedPath: "associatedResources.partners",
|
|
3429
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_PARTNER
|
|
3430
|
+
};
|
|
3431
|
+
}
|
|
3432
|
+
return {
|
|
3433
|
+
associatedField: "vendors",
|
|
3434
|
+
associatedPath: "associatedResources.vendors",
|
|
3435
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_VENDOR
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
var ASSOCIABLE_MODELS = {
|
|
3439
|
+
[import_cluemart_shared28.EnumResourceType.EVENT]: EventModel,
|
|
3440
|
+
[import_cluemart_shared28.EnumResourceType.PARTNER]: PartnerModel,
|
|
3441
|
+
[import_cluemart_shared28.EnumResourceType.VENDOR]: VendorModel
|
|
3442
|
+
};
|
|
3443
|
+
function acceptedAssociateUserIds(associates) {
|
|
3444
|
+
return (associates ?? []).filter((associate) => associate.status === import_cluemart_shared28.EnumAssociateStatus.ACCEPTED).map((associate) => associate.userId);
|
|
3445
|
+
}
|
|
3446
|
+
async function detachUsersFromResource({
|
|
3447
|
+
resourceId,
|
|
3448
|
+
resourceType,
|
|
3449
|
+
userIds
|
|
3450
|
+
}) {
|
|
3451
|
+
if (userIds.length === 0) return;
|
|
3452
|
+
const { associateRole, associatedPath: path } = getAssociateAccessMeta(resourceType);
|
|
3453
|
+
const removedResourceId = typeof resourceId === "string" ? new import_mongoose42.default.Types.ObjectId(resourceId) : resourceId;
|
|
3454
|
+
await UserModel.updateMany({ _id: { $in: userIds } }, [
|
|
3455
|
+
{
|
|
3456
|
+
$set: {
|
|
3457
|
+
[path]: {
|
|
3458
|
+
$setDifference: [{ $ifNull: [`$${path}`, []] }, [removedResourceId]]
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
},
|
|
3462
|
+
{
|
|
3463
|
+
$set: {
|
|
3464
|
+
roles: {
|
|
3465
|
+
$cond: [
|
|
3466
|
+
{ $eq: [{ $size: { $ifNull: [`$${path}`, []] } }, 0] },
|
|
3467
|
+
{
|
|
3468
|
+
$setDifference: [{ $ifNull: ["$roles", []] }, [associateRole]]
|
|
3469
|
+
},
|
|
3470
|
+
"$roles"
|
|
3471
|
+
]
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
]).exec();
|
|
3476
|
+
}
|
|
3477
|
+
async function acceptedUserIdsForResource({
|
|
3478
|
+
resourceId,
|
|
3479
|
+
resourceType
|
|
3480
|
+
}) {
|
|
3481
|
+
const model = ASSOCIABLE_MODELS[resourceType];
|
|
3482
|
+
const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates").lean().exec();
|
|
3483
|
+
return new Set(
|
|
3484
|
+
acceptedAssociateUserIds(resource?.associates).map(
|
|
3485
|
+
(userId) => String(userId)
|
|
3486
|
+
)
|
|
3487
|
+
);
|
|
3488
|
+
}
|
|
3489
|
+
async function grantAssociateGrants({
|
|
3490
|
+
resourceId,
|
|
3491
|
+
resourceType,
|
|
3492
|
+
userIds
|
|
3493
|
+
}) {
|
|
3494
|
+
if (userIds.length === 0) return;
|
|
3495
|
+
const acceptedUserIds = await acceptedUserIdsForResource({
|
|
3496
|
+
resourceId,
|
|
3497
|
+
resourceType
|
|
3498
|
+
});
|
|
3499
|
+
const grantUserIds = userIds.filter(
|
|
3500
|
+
(userId) => acceptedUserIds.has(String(userId))
|
|
3501
|
+
);
|
|
3502
|
+
if (grantUserIds.length === 0) return;
|
|
3503
|
+
const { associateRole, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3504
|
+
await UserModel.updateMany(
|
|
3505
|
+
{ _id: { $in: grantUserIds } },
|
|
3506
|
+
{
|
|
3507
|
+
$addToSet: {
|
|
3508
|
+
[associatedPath]: resourceId,
|
|
3509
|
+
roles: associateRole
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
).exec();
|
|
3513
|
+
}
|
|
3514
|
+
async function detachUnlessStillAccepted({
|
|
3515
|
+
resourceId,
|
|
3516
|
+
resourceType,
|
|
3517
|
+
userIds
|
|
3518
|
+
}) {
|
|
3519
|
+
if (userIds.length === 0) return [];
|
|
3520
|
+
await detachUsersFromResource({ resourceId, resourceType, userIds });
|
|
3521
|
+
const acceptedAfterDetach = await acceptedUserIdsForResource({
|
|
3522
|
+
resourceId,
|
|
3523
|
+
resourceType
|
|
3524
|
+
});
|
|
3525
|
+
const restoredUserIds = userIds.filter(
|
|
3526
|
+
(userId) => acceptedAfterDetach.has(String(userId))
|
|
3527
|
+
);
|
|
3528
|
+
if (restoredUserIds.length === 0) return userIds;
|
|
3529
|
+
await grantAssociateGrants({
|
|
3530
|
+
resourceId,
|
|
3531
|
+
resourceType,
|
|
3532
|
+
userIds: restoredUserIds
|
|
3533
|
+
});
|
|
3534
|
+
const acceptedAfterRestore = await acceptedUserIdsForResource({
|
|
3535
|
+
resourceId,
|
|
3536
|
+
resourceType
|
|
3537
|
+
});
|
|
3538
|
+
const regressedUserIds = restoredUserIds.filter(
|
|
3539
|
+
(userId) => !acceptedAfterRestore.has(String(userId))
|
|
3540
|
+
);
|
|
3541
|
+
if (regressedUserIds.length > 0) {
|
|
3542
|
+
await detachUsersFromResource({
|
|
3543
|
+
resourceId,
|
|
3544
|
+
resourceType,
|
|
3545
|
+
userIds: regressedUserIds
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
return userIds.filter((userId) => !acceptedAfterRestore.has(String(userId)));
|
|
3549
|
+
}
|
|
3550
|
+
async function detachStaleAssociateGrants({
|
|
3551
|
+
acceptedUserIds,
|
|
3552
|
+
resourceId,
|
|
3553
|
+
resourceType
|
|
3554
|
+
}) {
|
|
3555
|
+
const { associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3556
|
+
const stale = await UserModel.find({
|
|
3557
|
+
_id: { $nin: acceptedUserIds },
|
|
3558
|
+
[associatedPath]: resourceId
|
|
3559
|
+
}).select("_id").lean().exec();
|
|
3560
|
+
const staleUserIds = stale.map((user) => user._id);
|
|
3561
|
+
return detachUnlessStillAccepted({
|
|
3562
|
+
resourceId,
|
|
3563
|
+
resourceType,
|
|
3564
|
+
userIds: staleUserIds
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
async function detachAssociateGrantsForResources({
|
|
3568
|
+
resources
|
|
3569
|
+
}) {
|
|
3570
|
+
const result = resources.map((resource) => ({
|
|
3571
|
+
detachedUserIds: [],
|
|
3572
|
+
resourceId: resource.resourceId,
|
|
3573
|
+
resourceType: resource.resourceType
|
|
3574
|
+
}));
|
|
3575
|
+
const indexByType = /* @__PURE__ */ new Map();
|
|
3576
|
+
resources.forEach((resource, index) => {
|
|
3577
|
+
const entries = indexByType.get(resource.resourceType) ?? [];
|
|
3578
|
+
entries.push({ index, resourceId: resource.resourceId });
|
|
3579
|
+
indexByType.set(resource.resourceType, entries);
|
|
3580
|
+
});
|
|
3581
|
+
for (const [resourceType, entries] of indexByType) {
|
|
3582
|
+
const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3583
|
+
const resourceIds = entries.map((entry) => entry.resourceId);
|
|
3584
|
+
const wanted = new Set(resourceIds.map((resourceId) => String(resourceId)));
|
|
3585
|
+
const holders = await UserModel.find({
|
|
3586
|
+
[associatedPath]: { $in: resourceIds }
|
|
3587
|
+
}).select("_id associatedResources").lean().exec();
|
|
3588
|
+
const userIdsByResource = /* @__PURE__ */ new Map();
|
|
3589
|
+
for (const user of holders) {
|
|
3590
|
+
for (const heldResourceId of user.associatedResources?.[associatedField] ?? []) {
|
|
3591
|
+
const key = String(heldResourceId);
|
|
3592
|
+
if (!wanted.has(key)) continue;
|
|
3593
|
+
const userIds = userIdsByResource.get(key) ?? [];
|
|
3594
|
+
userIds.push(user._id);
|
|
3595
|
+
userIdsByResource.set(key, userIds);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
for (const entry of entries) {
|
|
3599
|
+
const userIds = userIdsByResource.get(String(entry.resourceId));
|
|
3600
|
+
if (!userIds || userIds.length === 0) continue;
|
|
3601
|
+
await detachUsersFromResource({
|
|
3602
|
+
resourceId: entry.resourceId,
|
|
3603
|
+
resourceType,
|
|
3604
|
+
userIds
|
|
3605
|
+
});
|
|
3606
|
+
result[entry.index].detachedUserIds = userIds;
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
return result;
|
|
3610
|
+
}
|
|
3611
|
+
var DEFAULT_RECONCILE_BATCH_SIZE = 500;
|
|
3612
|
+
async function reconcileUserBatch({
|
|
3613
|
+
associatedField,
|
|
3614
|
+
model,
|
|
3615
|
+
resourceType,
|
|
3616
|
+
users
|
|
3617
|
+
}) {
|
|
3618
|
+
const heldByResource = /* @__PURE__ */ new Map();
|
|
3619
|
+
for (const user of users) {
|
|
3620
|
+
for (const resourceId of user.associatedResources?.[associatedField] ?? []) {
|
|
3621
|
+
const key = String(resourceId);
|
|
3622
|
+
const entry = heldByResource.get(key) ?? { resourceId, userIds: [] };
|
|
3623
|
+
entry.userIds.push(user._id);
|
|
3624
|
+
heldByResource.set(key, entry);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
if (heldByResource.size === 0) return 0;
|
|
3628
|
+
const resources = await model.find({
|
|
3629
|
+
_id: {
|
|
3630
|
+
$in: [...heldByResource.values()].map((entry) => entry.resourceId)
|
|
3631
|
+
}
|
|
3632
|
+
}).select("associates deletedAt").lean().exec();
|
|
3633
|
+
const acceptedByResource = /* @__PURE__ */ new Map();
|
|
3634
|
+
for (const resource of resources) {
|
|
3635
|
+
acceptedByResource.set(
|
|
3636
|
+
String(resource._id),
|
|
3637
|
+
resource.deletedAt ? /* @__PURE__ */ new Set() : new Set(
|
|
3638
|
+
acceptedAssociateUserIds(resource.associates).map(
|
|
3639
|
+
(userId) => String(userId)
|
|
3640
|
+
)
|
|
3641
|
+
)
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
let detachedGrants = 0;
|
|
3645
|
+
for (const [key, { resourceId, userIds }] of heldByResource) {
|
|
3646
|
+
const accepted = acceptedByResource.get(key);
|
|
3647
|
+
const staleUserIds = userIds.filter(
|
|
3648
|
+
(userId) => !accepted?.has(String(userId))
|
|
3649
|
+
);
|
|
3650
|
+
if (staleUserIds.length === 0) continue;
|
|
3651
|
+
const removedUserIds = await detachUnlessStillAccepted({
|
|
3652
|
+
resourceId,
|
|
3653
|
+
resourceType,
|
|
3654
|
+
userIds: staleUserIds
|
|
3655
|
+
});
|
|
3656
|
+
detachedGrants += removedUserIds.length;
|
|
3657
|
+
}
|
|
3658
|
+
return detachedGrants;
|
|
3659
|
+
}
|
|
3660
|
+
async function reconcileResourceType({
|
|
3661
|
+
batchSize,
|
|
3662
|
+
resourceType
|
|
3663
|
+
}) {
|
|
3664
|
+
const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3665
|
+
const model = ASSOCIABLE_MODELS[resourceType];
|
|
3666
|
+
const result = {
|
|
3667
|
+
detachedGrants: 0,
|
|
3668
|
+
scannedUsers: 0
|
|
3669
|
+
};
|
|
3670
|
+
let lastId = null;
|
|
3671
|
+
for (; ; ) {
|
|
3672
|
+
const users = await UserModel.find({
|
|
3673
|
+
...lastId ? { _id: { $gt: lastId } } : {},
|
|
3674
|
+
[associatedPath]: { $exists: true, $ne: [] }
|
|
3675
|
+
}).sort({ _id: 1 }).limit(batchSize).select("_id associatedResources").lean().exec();
|
|
3676
|
+
if (users.length === 0) break;
|
|
3677
|
+
result.scannedUsers += users.length;
|
|
3678
|
+
lastId = users[users.length - 1]._id;
|
|
3679
|
+
result.detachedGrants += await reconcileUserBatch({
|
|
3680
|
+
associatedField,
|
|
3681
|
+
model,
|
|
3682
|
+
resourceType,
|
|
3683
|
+
users
|
|
3684
|
+
});
|
|
3685
|
+
}
|
|
3686
|
+
return result;
|
|
3687
|
+
}
|
|
3688
|
+
async function reconcileAssociateGrants({
|
|
3689
|
+
batchSize = DEFAULT_RECONCILE_BATCH_SIZE
|
|
3690
|
+
} = {}) {
|
|
3691
|
+
const totals = {
|
|
3692
|
+
detachedGrants: 0,
|
|
3693
|
+
scannedUsers: 0
|
|
3694
|
+
};
|
|
3695
|
+
for (const resourceType of [
|
|
3696
|
+
import_cluemart_shared28.EnumResourceType.EVENT,
|
|
3697
|
+
import_cluemart_shared28.EnumResourceType.VENDOR,
|
|
3698
|
+
import_cluemart_shared28.EnumResourceType.PARTNER
|
|
3699
|
+
]) {
|
|
3700
|
+
const result = await reconcileResourceType({ batchSize, resourceType });
|
|
3701
|
+
totals.detachedGrants += result.detachedGrants;
|
|
3702
|
+
totals.scannedUsers += result.scannedUsers;
|
|
3703
|
+
}
|
|
3704
|
+
return totals;
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3321
3707
|
// src/service/database.ts
|
|
3322
|
-
var
|
|
3708
|
+
var import_mongoose44 = __toESM(require("mongoose"));
|
|
3323
3709
|
|
|
3324
3710
|
// src/service/indexes.ts
|
|
3325
|
-
var
|
|
3711
|
+
var import_mongoose43 = __toESM(require("mongoose"));
|
|
3326
3712
|
function registeredModels() {
|
|
3327
|
-
return
|
|
3328
|
-
const model =
|
|
3713
|
+
return import_mongoose43.default.modelNames().map((modelName) => {
|
|
3714
|
+
const model = import_mongoose43.default.model(modelName);
|
|
3329
3715
|
return { createIndexes: () => model.createIndexes(), modelName };
|
|
3330
3716
|
});
|
|
3331
3717
|
}
|
|
@@ -3367,7 +3753,7 @@ var connectToDatabase = async ({
|
|
|
3367
3753
|
// Fallback to MongoDB Atlas connection string
|
|
3368
3754
|
`mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
|
|
3369
3755
|
);
|
|
3370
|
-
await
|
|
3756
|
+
await import_mongoose44.default.connect(mongoUri);
|
|
3371
3757
|
const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
|
|
3372
3758
|
console.log(
|
|
3373
3759
|
`${connectionType} connected from server/src/service/database.ts`
|
|
@@ -3383,7 +3769,7 @@ var connectToDatabase = async ({
|
|
|
3383
3769
|
|
|
3384
3770
|
// src/types/index.ts
|
|
3385
3771
|
var import_express = __toESM(require("express"));
|
|
3386
|
-
var
|
|
3772
|
+
var import_mongoose45 = __toESM(require("mongoose"));
|
|
3387
3773
|
|
|
3388
3774
|
// src/service/notifyUsers.ts
|
|
3389
3775
|
async function publishNotificationEvents(userId, pubsub) {
|
|
@@ -3431,9 +3817,9 @@ async function notifyUsers({
|
|
|
3431
3817
|
}
|
|
3432
3818
|
|
|
3433
3819
|
// src/service/updateAdStatus.ts
|
|
3434
|
-
var
|
|
3820
|
+
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
3435
3821
|
async function updateAdStatuses() {
|
|
3436
|
-
const now = (0,
|
|
3822
|
+
const now = (0, import_cluemart_shared29.nzDayKey)();
|
|
3437
3823
|
const invalidResult = await AdModel.updateMany(
|
|
3438
3824
|
{
|
|
3439
3825
|
$or: [
|
|
@@ -3441,50 +3827,50 @@ async function updateAdStatuses() {
|
|
|
3441
3827
|
{ end: { $exists: false } },
|
|
3442
3828
|
{ $expr: { $gt: ["$start", "$end"] } }
|
|
3443
3829
|
],
|
|
3444
|
-
status: { $ne:
|
|
3830
|
+
status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED }
|
|
3445
3831
|
},
|
|
3446
|
-
{ $set: { status:
|
|
3832
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3447
3833
|
);
|
|
3448
3834
|
const expiredResult = await AdModel.updateMany(
|
|
3449
|
-
{ end: { $lte: now }, status: { $ne:
|
|
3450
|
-
{ $set: { status:
|
|
3835
|
+
{ end: { $lte: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.EXPIRED } },
|
|
3836
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.EXPIRED } }
|
|
3451
3837
|
);
|
|
3452
3838
|
const eligibleBooking = {
|
|
3453
3839
|
$or: [
|
|
3454
3840
|
{ bookingKind: { $exists: false } },
|
|
3455
3841
|
{ bookingKind: null },
|
|
3456
3842
|
{
|
|
3457
|
-
approvalStatus:
|
|
3458
|
-
bookingKind:
|
|
3843
|
+
approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
|
|
3844
|
+
bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.RESERVED
|
|
3459
3845
|
},
|
|
3460
3846
|
{
|
|
3461
|
-
approvalStatus:
|
|
3462
|
-
bookingKind:
|
|
3463
|
-
paymentStatus:
|
|
3847
|
+
approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
|
|
3848
|
+
bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.PAID,
|
|
3849
|
+
paymentStatus: import_cluemart_shared29.EnumAdPaymentStatus.PAID
|
|
3464
3850
|
}
|
|
3465
3851
|
]
|
|
3466
3852
|
};
|
|
3467
3853
|
const awaitingApprovalResult = await AdModel.updateMany(
|
|
3468
3854
|
{
|
|
3469
3855
|
$nor: eligibleBooking.$or,
|
|
3470
|
-
bookingKind: { $in: Object.values(
|
|
3856
|
+
bookingKind: { $in: Object.values(import_cluemart_shared29.EnumAdBookingSlotKind) },
|
|
3471
3857
|
end: { $gt: now },
|
|
3472
|
-
status:
|
|
3858
|
+
status: import_cluemart_shared29.EnumAdStatus.ACTIVE
|
|
3473
3859
|
},
|
|
3474
|
-
{ $set: { status:
|
|
3860
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3475
3861
|
);
|
|
3476
3862
|
const activeResult = await AdModel.updateMany(
|
|
3477
3863
|
{
|
|
3478
3864
|
end: { $gt: now },
|
|
3479
3865
|
start: { $lte: now },
|
|
3480
|
-
status: { $ne:
|
|
3866
|
+
status: { $ne: import_cluemart_shared29.EnumAdStatus.ACTIVE },
|
|
3481
3867
|
...eligibleBooking
|
|
3482
3868
|
},
|
|
3483
|
-
{ $set: { status:
|
|
3869
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.ACTIVE } }
|
|
3484
3870
|
);
|
|
3485
3871
|
const pausedResult = await AdModel.updateMany(
|
|
3486
|
-
{ start: { $gt: now }, status: { $ne:
|
|
3487
|
-
{ $set: { status:
|
|
3872
|
+
{ start: { $gt: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED } },
|
|
3873
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3488
3874
|
);
|
|
3489
3875
|
console.log(
|
|
3490
3876
|
`\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
|
|
@@ -3492,15 +3878,15 @@ async function updateAdStatuses() {
|
|
|
3492
3878
|
}
|
|
3493
3879
|
|
|
3494
3880
|
// src/service/objectIdToString.ts
|
|
3495
|
-
var
|
|
3881
|
+
var import_mongoose47 = __toESM(require("mongoose"));
|
|
3496
3882
|
function isValidObjectId(value) {
|
|
3497
|
-
return
|
|
3883
|
+
return import_mongoose47.default.Types.ObjectId.isValid(value);
|
|
3498
3884
|
}
|
|
3499
3885
|
function convertObjectIdsToStrings(obj) {
|
|
3500
3886
|
if (obj === null || obj === void 0) {
|
|
3501
3887
|
return obj;
|
|
3502
3888
|
}
|
|
3503
|
-
if (obj instanceof
|
|
3889
|
+
if (obj instanceof import_mongoose47.default.Types.ObjectId) {
|
|
3504
3890
|
return obj.toString();
|
|
3505
3891
|
}
|
|
3506
3892
|
if (obj instanceof Date) {
|
|
@@ -3694,19 +4080,19 @@ function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
|
|
|
3694
4080
|
}
|
|
3695
4081
|
|
|
3696
4082
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3697
|
-
var
|
|
4083
|
+
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3698
4084
|
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3699
4085
|
|
|
3700
4086
|
// src/service/event/archiveEndedEventDates.ts
|
|
3701
|
-
var
|
|
4087
|
+
var import_cluemart_shared30 = require("@timardex/cluemart-shared");
|
|
3702
4088
|
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3703
4089
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3704
4090
|
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
3705
4091
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3706
|
-
|
|
4092
|
+
import_cluemart_shared30.EnumEventDateStatus.ENDED
|
|
3707
4093
|
]);
|
|
3708
4094
|
var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
|
|
3709
|
-
|
|
4095
|
+
import_cluemart_shared30.EnumEventDateStatus.INVALID
|
|
3710
4096
|
]);
|
|
3711
4097
|
function splitEventDatesForArchive(dateTime) {
|
|
3712
4098
|
return {
|
|
@@ -3729,12 +4115,12 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
|
3729
4115
|
});
|
|
3730
4116
|
}
|
|
3731
4117
|
function isPastCanceledEventDate(slot, now) {
|
|
3732
|
-
if (slot.dateStatus !==
|
|
4118
|
+
if (slot.dateStatus !== import_cluemart_shared30.EnumEventDateStatus.CANCELED) {
|
|
3733
4119
|
return false;
|
|
3734
4120
|
}
|
|
3735
4121
|
const endDateTime = (0, import_dayjs3.default)(
|
|
3736
4122
|
`${slot.endDate} ${slot.endTime}`,
|
|
3737
|
-
`${
|
|
4123
|
+
`${import_cluemart_shared30.dateFormat} ${import_cluemart_shared30.timeFormat}`,
|
|
3738
4124
|
true
|
|
3739
4125
|
);
|
|
3740
4126
|
return endDateTime.isValid() && endDateTime.isBefore(now);
|
|
@@ -3780,7 +4166,7 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3780
4166
|
try {
|
|
3781
4167
|
for await (const doc of cursor) {
|
|
3782
4168
|
const dateTime = doc.dateTime.map(
|
|
3783
|
-
(slot) => (0,
|
|
4169
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3784
4170
|
);
|
|
3785
4171
|
if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
|
|
3786
4172
|
continue;
|
|
@@ -3804,9 +4190,9 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3804
4190
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
3805
4191
|
"dateTime.dateStatus": {
|
|
3806
4192
|
$in: [
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
4193
|
+
import_cluemart_shared31.EnumEventDateStatus.ENDED,
|
|
4194
|
+
import_cluemart_shared31.EnumEventDateStatus.INVALID,
|
|
4195
|
+
import_cluemart_shared31.EnumEventDateStatus.CANCELED
|
|
3810
4196
|
]
|
|
3811
4197
|
},
|
|
3812
4198
|
deletedAt: null
|
|
@@ -3831,7 +4217,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3831
4217
|
try {
|
|
3832
4218
|
for await (const doc of cursor) {
|
|
3833
4219
|
const updated = doc.dateTime.map(
|
|
3834
|
-
(slot) => (0,
|
|
4220
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3835
4221
|
);
|
|
3836
4222
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3837
4223
|
const pastCanceled = updated.filter(
|
|
@@ -3855,13 +4241,13 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3855
4241
|
if (archive.length > 0 || discard.length > 0) {
|
|
3856
4242
|
pullConditions.push({
|
|
3857
4243
|
dateStatus: {
|
|
3858
|
-
$in: [
|
|
4244
|
+
$in: [import_cluemart_shared31.EnumEventDateStatus.ENDED, import_cluemart_shared31.EnumEventDateStatus.INVALID]
|
|
3859
4245
|
}
|
|
3860
4246
|
});
|
|
3861
4247
|
}
|
|
3862
4248
|
for (const slot of pastCanceled) {
|
|
3863
4249
|
pullConditions.push({
|
|
3864
|
-
dateStatus:
|
|
4250
|
+
dateStatus: import_cluemart_shared31.EnumEventDateStatus.CANCELED,
|
|
3865
4251
|
startDate: slot.startDate,
|
|
3866
4252
|
startTime: slot.startTime
|
|
3867
4253
|
});
|
|
@@ -3903,9 +4289,9 @@ async function cleanEventInfoDates(now) {
|
|
|
3903
4289
|
try {
|
|
3904
4290
|
for await (const doc of cursor) {
|
|
3905
4291
|
const updated = doc.dateTime.map(
|
|
3906
|
-
(slot) => (0,
|
|
4292
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3907
4293
|
);
|
|
3908
|
-
const kept = (0,
|
|
4294
|
+
const kept = (0, import_cluemart_shared31.filterDatesByFutureStatus)(updated);
|
|
3909
4295
|
if (kept.length === updated.length) {
|
|
3910
4296
|
continue;
|
|
3911
4297
|
}
|
|
@@ -3955,7 +4341,7 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
3955
4341
|
}
|
|
3956
4342
|
|
|
3957
4343
|
// src/service/index.ts
|
|
3958
|
-
var
|
|
4344
|
+
var import_cluemart_shared39 = require("@timardex/cluemart-shared");
|
|
3959
4345
|
|
|
3960
4346
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
3961
4347
|
async function findEventOrImportedMarketById(resourceId) {
|
|
@@ -3972,7 +4358,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
3972
4358
|
}
|
|
3973
4359
|
|
|
3974
4360
|
// src/service/relations.ts
|
|
3975
|
-
var
|
|
4361
|
+
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3976
4362
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
3977
4363
|
if (!previousDateTime?.length) {
|
|
3978
4364
|
return false;
|
|
@@ -3988,8 +4374,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
|
3988
4374
|
return false;
|
|
3989
4375
|
}
|
|
3990
4376
|
return previousDateTime.some(
|
|
3991
|
-
(prev) => prev.dateStatus ===
|
|
3992
|
-
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus ===
|
|
4377
|
+
(prev) => prev.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
4378
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED
|
|
3993
4379
|
)
|
|
3994
4380
|
);
|
|
3995
4381
|
}
|
|
@@ -4000,7 +4386,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4000
4386
|
) ?? false;
|
|
4001
4387
|
return {
|
|
4002
4388
|
...relationDate,
|
|
4003
|
-
status: existsInEvent ? relationDate.status :
|
|
4389
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared32.EnumInviteStatus.CANCELED
|
|
4004
4390
|
};
|
|
4005
4391
|
});
|
|
4006
4392
|
}
|
|
@@ -4009,15 +4395,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4009
4395
|
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4010
4396
|
|
|
4011
4397
|
// src/service/license/compliance/utils.ts
|
|
4012
|
-
var
|
|
4398
|
+
var import_cluemart_shared37 = require("@timardex/cluemart-shared");
|
|
4013
4399
|
var import_dayjs7 = __toESM(require("dayjs"));
|
|
4014
4400
|
|
|
4015
4401
|
// src/service/license/compliance/event.ts
|
|
4016
|
-
var
|
|
4402
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
4017
4403
|
var eventLicences = [
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4404
|
+
import_cluemart_shared33.EnumUserLicence.STANDARD_EVENT,
|
|
4405
|
+
import_cluemart_shared33.EnumUserLicence.PRO_EVENT,
|
|
4406
|
+
import_cluemart_shared33.EnumUserLicence.PRO_PLUS_EVENT
|
|
4021
4407
|
];
|
|
4022
4408
|
async function handleEventLicenceCompliance(user, now) {
|
|
4023
4409
|
if (!user.licences || !user.events?.length) {
|
|
@@ -4229,9 +4615,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
4229
4615
|
}
|
|
4230
4616
|
|
|
4231
4617
|
// src/service/license/compliance/partner.ts
|
|
4232
|
-
var
|
|
4618
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4233
4619
|
var partnerLicences = [
|
|
4234
|
-
|
|
4620
|
+
import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
|
|
4235
4621
|
];
|
|
4236
4622
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
4237
4623
|
if (!user.licences || !user.partner) {
|
|
@@ -4241,52 +4627,62 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
4241
4627
|
}
|
|
4242
4628
|
|
|
4243
4629
|
// src/service/license/compliance/vendor.ts
|
|
4244
|
-
var
|
|
4630
|
+
var import_cluemart_shared36 = require("@timardex/cluemart-shared");
|
|
4245
4631
|
var import_dayjs6 = __toESM(require("dayjs"));
|
|
4246
4632
|
|
|
4247
4633
|
// src/service/license/models.ts
|
|
4248
|
-
var
|
|
4634
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
4249
4635
|
var import_dayjs5 = __toESM(require("dayjs"));
|
|
4250
4636
|
var import_graphql = require("graphql");
|
|
4251
|
-
var LicenceCategory = /* @__PURE__ */ ((
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
return
|
|
4637
|
+
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
4638
|
+
LicenceCategory3["EVENT"] = "event";
|
|
4639
|
+
LicenceCategory3["PARTNER"] = "partner";
|
|
4640
|
+
LicenceCategory3["VENDOR"] = "vendor";
|
|
4641
|
+
LicenceCategory3["AFFILIATE"] = "affiliate";
|
|
4642
|
+
LicenceCategory3["SCHOOL"] = "school";
|
|
4643
|
+
return LicenceCategory3;
|
|
4258
4644
|
})(LicenceCategory || {});
|
|
4259
4645
|
var licenceCategoryMapping = {
|
|
4260
|
-
[
|
|
4261
|
-
[
|
|
4262
|
-
[
|
|
4263
|
-
[
|
|
4264
|
-
[
|
|
4265
|
-
[
|
|
4266
|
-
[
|
|
4267
|
-
[
|
|
4268
|
-
[
|
|
4646
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
|
|
4647
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
|
|
4648
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
|
|
4649
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
|
|
4650
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
|
|
4651
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
|
|
4652
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
|
|
4653
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4654
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
|
|
4269
4655
|
};
|
|
4270
4656
|
var licencePriority = {
|
|
4271
|
-
[
|
|
4272
|
-
[
|
|
4273
|
-
[
|
|
4274
|
-
[
|
|
4275
|
-
[
|
|
4276
|
-
[
|
|
4277
|
-
[
|
|
4278
|
-
[
|
|
4279
|
-
[
|
|
4657
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: 3,
|
|
4658
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: 2,
|
|
4659
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: 1,
|
|
4660
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
|
|
4661
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: 2,
|
|
4662
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: 1,
|
|
4663
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: 1,
|
|
4664
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: 1,
|
|
4665
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: 1
|
|
4280
4666
|
};
|
|
4281
4667
|
var standardLicences = [
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4668
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
|
|
4669
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
|
|
4670
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
|
|
4285
4671
|
];
|
|
4286
4672
|
var standardLicenceSet = new Set(standardLicences);
|
|
4287
4673
|
function isStandardLicence(licence) {
|
|
4288
4674
|
return standardLicenceSet.has(licence);
|
|
4289
4675
|
}
|
|
4676
|
+
var proLicences = [
|
|
4677
|
+
import_cluemart_shared35.EnumUserLicence.PRO_EVENT,
|
|
4678
|
+
import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT,
|
|
4679
|
+
import_cluemart_shared35.EnumUserLicence.PRO_VENDOR,
|
|
4680
|
+
import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR
|
|
4681
|
+
];
|
|
4682
|
+
var proLicenceSet = new Set(proLicences);
|
|
4683
|
+
function isProLicence(licence) {
|
|
4684
|
+
return proLicenceSet.has(licence);
|
|
4685
|
+
}
|
|
4290
4686
|
var categoryRegexMapping = {
|
|
4291
4687
|
["event" /* EVENT */]: /_event$/,
|
|
4292
4688
|
["partner" /* PARTNER */]: /_partner$/,
|
|
@@ -4295,11 +4691,11 @@ var categoryRegexMapping = {
|
|
|
4295
4691
|
["school" /* SCHOOL */]: /_school$/
|
|
4296
4692
|
};
|
|
4297
4693
|
var categoryFallbackLicence = {
|
|
4298
|
-
["event" /* EVENT */]:
|
|
4299
|
-
["partner" /* PARTNER */]:
|
|
4300
|
-
["vendor" /* VENDOR */]:
|
|
4301
|
-
["affiliate" /* AFFILIATE */]:
|
|
4302
|
-
["school" /* SCHOOL */]:
|
|
4694
|
+
["event" /* EVENT */]: import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
|
|
4695
|
+
["partner" /* PARTNER */]: import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER,
|
|
4696
|
+
["vendor" /* VENDOR */]: import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
|
|
4697
|
+
["affiliate" /* AFFILIATE */]: import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE,
|
|
4698
|
+
["school" /* SCHOOL */]: import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL
|
|
4303
4699
|
};
|
|
4304
4700
|
var LicenceFilterInput = {
|
|
4305
4701
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -4329,11 +4725,11 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
4329
4725
|
function createLicenceObject(expiryDate, licenceType) {
|
|
4330
4726
|
const today = (0, import_dayjs5.default)();
|
|
4331
4727
|
const expiryDateMapping = {
|
|
4332
|
-
[
|
|
4333
|
-
[
|
|
4334
|
-
[
|
|
4335
|
-
[
|
|
4336
|
-
[
|
|
4728
|
+
[import_cluemart_shared35.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
4729
|
+
[import_cluemart_shared35.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
4730
|
+
[import_cluemart_shared35.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
|
|
4731
|
+
[import_cluemart_shared35.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
|
|
4732
|
+
[import_cluemart_shared35.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
|
|
4337
4733
|
};
|
|
4338
4734
|
const licenceObject = {
|
|
4339
4735
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -4437,13 +4833,13 @@ async function checkOwnerHasLicence({
|
|
|
4437
4833
|
const owner = await UserModel.findById(userId);
|
|
4438
4834
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
4439
4835
|
const categoryByResource = {
|
|
4440
|
-
[
|
|
4441
|
-
[
|
|
4442
|
-
[
|
|
4443
|
-
[
|
|
4444
|
-
[
|
|
4836
|
+
[import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4837
|
+
[import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4838
|
+
[import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
|
|
4839
|
+
[import_cluemart_shared35.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4840
|
+
[import_cluemart_shared35.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
|
|
4445
4841
|
};
|
|
4446
|
-
if (!(0,
|
|
4842
|
+
if (!(0, import_cluemart_shared35.isNonVisitorResourceType)(resourceType)) {
|
|
4447
4843
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
4448
4844
|
}
|
|
4449
4845
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -4465,6 +4861,128 @@ async function checkOwnerHasLicence({
|
|
|
4465
4861
|
);
|
|
4466
4862
|
}
|
|
4467
4863
|
}
|
|
4864
|
+
var resourceLicenceCategory = {
|
|
4865
|
+
[import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4866
|
+
[import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4867
|
+
[import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
|
|
4868
|
+
};
|
|
4869
|
+
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4870
|
+
const stripe = user.stripe;
|
|
4871
|
+
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4872
|
+
return false;
|
|
4873
|
+
}
|
|
4874
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4875
|
+
const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
4876
|
+
if (hasActivePaymentGracePeriod) {
|
|
4877
|
+
return true;
|
|
4878
|
+
}
|
|
4879
|
+
if (!stripe.subscriptionId) {
|
|
4880
|
+
return false;
|
|
4881
|
+
}
|
|
4882
|
+
if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
|
|
4883
|
+
return false;
|
|
4884
|
+
}
|
|
4885
|
+
if (!stripe.endDate) {
|
|
4886
|
+
return false;
|
|
4887
|
+
}
|
|
4888
|
+
const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
|
|
4889
|
+
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4890
|
+
}
|
|
4891
|
+
function effectiveLicences({
|
|
4892
|
+
includeStripeProtected = false,
|
|
4893
|
+
licences,
|
|
4894
|
+
now,
|
|
4895
|
+
owner
|
|
4896
|
+
}) {
|
|
4897
|
+
const nowDayjs = (0, import_dayjs5.default)(now);
|
|
4898
|
+
return (licences ?? []).filter((licence) => {
|
|
4899
|
+
if (!licence.licenceType || licence.expiryDate == null) {
|
|
4900
|
+
return false;
|
|
4901
|
+
}
|
|
4902
|
+
if (new Date(licence.expiryDate).getTime() > now.getTime()) {
|
|
4903
|
+
return true;
|
|
4904
|
+
}
|
|
4905
|
+
return Boolean(
|
|
4906
|
+
includeStripeProtected && owner && isProtectedByCurrentStripeSubscription(
|
|
4907
|
+
owner,
|
|
4908
|
+
licence.licenceType,
|
|
4909
|
+
nowDayjs
|
|
4910
|
+
)
|
|
4911
|
+
);
|
|
4912
|
+
});
|
|
4913
|
+
}
|
|
4914
|
+
async function getActiveLicenceForResource({
|
|
4915
|
+
includeStripeProtected = false,
|
|
4916
|
+
userId,
|
|
4917
|
+
resourceType,
|
|
4918
|
+
now = /* @__PURE__ */ new Date()
|
|
4919
|
+
}) {
|
|
4920
|
+
const category = resourceLicenceCategory[resourceType];
|
|
4921
|
+
if (!category) {
|
|
4922
|
+
return null;
|
|
4923
|
+
}
|
|
4924
|
+
const owner = await UserModel.findById(userId, {
|
|
4925
|
+
licences: 1,
|
|
4926
|
+
...includeStripeProtected ? { stripe: 1 } : {}
|
|
4927
|
+
}).lean();
|
|
4928
|
+
if (!owner?.licences?.length) {
|
|
4929
|
+
return null;
|
|
4930
|
+
}
|
|
4931
|
+
return getHighestLicenceForCategory(
|
|
4932
|
+
effectiveLicences({
|
|
4933
|
+
includeStripeProtected,
|
|
4934
|
+
licences: owner.licences,
|
|
4935
|
+
now,
|
|
4936
|
+
owner
|
|
4937
|
+
}),
|
|
4938
|
+
category
|
|
4939
|
+
);
|
|
4940
|
+
}
|
|
4941
|
+
async function getUserIdsWithActiveProLicence({
|
|
4942
|
+
includeStripeProtected = false,
|
|
4943
|
+
resourceType,
|
|
4944
|
+
userIds,
|
|
4945
|
+
now = /* @__PURE__ */ new Date()
|
|
4946
|
+
}) {
|
|
4947
|
+
const category = resourceLicenceCategory[resourceType];
|
|
4948
|
+
if (!category || userIds.length === 0) {
|
|
4949
|
+
return /* @__PURE__ */ new Set();
|
|
4950
|
+
}
|
|
4951
|
+
const owners = await UserModel.find(
|
|
4952
|
+
{ _id: { $in: userIds } },
|
|
4953
|
+
{ licences: 1, ...includeStripeProtected ? { stripe: 1 } : {} }
|
|
4954
|
+
).lean();
|
|
4955
|
+
const allowed = /* @__PURE__ */ new Set();
|
|
4956
|
+
for (const owner of owners ?? []) {
|
|
4957
|
+
const activeLicence = getHighestLicenceForCategory(
|
|
4958
|
+
effectiveLicences({
|
|
4959
|
+
includeStripeProtected,
|
|
4960
|
+
licences: owner.licences,
|
|
4961
|
+
now,
|
|
4962
|
+
owner
|
|
4963
|
+
}),
|
|
4964
|
+
category
|
|
4965
|
+
);
|
|
4966
|
+
if (activeLicence && isProLicence(activeLicence)) {
|
|
4967
|
+
allowed.add(String(owner._id));
|
|
4968
|
+
}
|
|
4969
|
+
}
|
|
4970
|
+
return allowed;
|
|
4971
|
+
}
|
|
4972
|
+
async function hasActiveProLicenceForResource({
|
|
4973
|
+
includeStripeProtected = false,
|
|
4974
|
+
userId,
|
|
4975
|
+
resourceType,
|
|
4976
|
+
now = /* @__PURE__ */ new Date()
|
|
4977
|
+
}) {
|
|
4978
|
+
const activeLicence = await getActiveLicenceForResource({
|
|
4979
|
+
includeStripeProtected,
|
|
4980
|
+
now,
|
|
4981
|
+
resourceType,
|
|
4982
|
+
userId
|
|
4983
|
+
});
|
|
4984
|
+
return activeLicence !== null && isProLicence(activeLicence);
|
|
4985
|
+
}
|
|
4468
4986
|
|
|
4469
4987
|
// src/service/license/compliance/vendor.ts
|
|
4470
4988
|
async function findUserVendor(userId, logLabel) {
|
|
@@ -4523,7 +5041,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
4523
5041
|
return (result?.matchedCount ?? 0) > 0;
|
|
4524
5042
|
}
|
|
4525
5043
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
4526
|
-
const isStandardVendor = licenceType ===
|
|
5044
|
+
const isStandardVendor = licenceType === import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR;
|
|
4527
5045
|
if (!isStandardVendor) {
|
|
4528
5046
|
return;
|
|
4529
5047
|
}
|
|
@@ -4570,7 +5088,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
4570
5088
|
return (result?.matchedCount ?? 0) > 0;
|
|
4571
5089
|
}
|
|
4572
5090
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
4573
|
-
const isProVendor = licenceType ===
|
|
5091
|
+
const isProVendor = licenceType === import_cluemart_shared36.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
4574
5092
|
if (!isProVendor) {
|
|
4575
5093
|
return;
|
|
4576
5094
|
}
|
|
@@ -4585,28 +5103,6 @@ async function restoreVendorProFeatures(userId, licenceType) {
|
|
|
4585
5103
|
throw error;
|
|
4586
5104
|
}
|
|
4587
5105
|
}
|
|
4588
|
-
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4589
|
-
const stripe = user.stripe;
|
|
4590
|
-
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4591
|
-
return false;
|
|
4592
|
-
}
|
|
4593
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4594
|
-
const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
4595
|
-
if (hasActivePaymentGracePeriod) {
|
|
4596
|
-
return true;
|
|
4597
|
-
}
|
|
4598
|
-
if (!stripe.subscriptionId) {
|
|
4599
|
-
return false;
|
|
4600
|
-
}
|
|
4601
|
-
if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
|
|
4602
|
-
return false;
|
|
4603
|
-
}
|
|
4604
|
-
if (!stripe.endDate) {
|
|
4605
|
-
return false;
|
|
4606
|
-
}
|
|
4607
|
-
const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
|
|
4608
|
-
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4609
|
-
}
|
|
4610
5106
|
async function handleVendorLicenceCompliance(user, now) {
|
|
4611
5107
|
if (!user.licences || !user.vendor) {
|
|
4612
5108
|
return;
|
|
@@ -4617,10 +5113,10 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4617
5113
|
if (vendorLicencesOfUser.length === 0) {
|
|
4618
5114
|
return;
|
|
4619
5115
|
}
|
|
4620
|
-
const
|
|
4621
|
-
(licence) => licence.licenceType !==
|
|
5116
|
+
const proLicences2 = vendorLicencesOfUser.filter(
|
|
5117
|
+
(licence) => licence.licenceType !== import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
|
|
4622
5118
|
);
|
|
4623
|
-
const expiredProLicences =
|
|
5119
|
+
const expiredProLicences = proLicences2.filter(
|
|
4624
5120
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4625
5121
|
);
|
|
4626
5122
|
const stripeProtectedLicenceTypes = new Set(
|
|
@@ -4631,7 +5127,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4631
5127
|
const expiredProLicence = expiredProLicences.some(
|
|
4632
5128
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4633
5129
|
);
|
|
4634
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(
|
|
5130
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared36.vendorLicences, now);
|
|
4635
5131
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4636
5132
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4637
5133
|
);
|
|
@@ -4647,7 +5143,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4647
5143
|
"owner.userId": user._id
|
|
4648
5144
|
}).lean().exec();
|
|
4649
5145
|
}
|
|
4650
|
-
const licencesToSync =
|
|
5146
|
+
const licencesToSync = import_cluemart_shared36.vendorLicences.filter(
|
|
4651
5147
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
4652
5148
|
);
|
|
4653
5149
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -4662,11 +5158,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4662
5158
|
data: {
|
|
4663
5159
|
resourceId: String(vendor._id),
|
|
4664
5160
|
resourceName: vendor.name,
|
|
4665
|
-
resourceType:
|
|
5161
|
+
resourceType: import_cluemart_shared36.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
4666
5162
|
},
|
|
4667
5163
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
4668
5164
|
title: `Vendor Licence Downgraded`,
|
|
4669
|
-
type:
|
|
5165
|
+
type: import_cluemart_shared36.EnumNotificationType.SYSTEM,
|
|
4670
5166
|
userIds: [user._id]
|
|
4671
5167
|
};
|
|
4672
5168
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -4680,26 +5176,11 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4680
5176
|
if (!vendor) {
|
|
4681
5177
|
return false;
|
|
4682
5178
|
}
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
return false;
|
|
4689
|
-
}
|
|
4690
|
-
const now = (0, import_dayjs6.default)();
|
|
4691
|
-
const effectiveVendorLicences = owner.licences?.filter(
|
|
4692
|
-
(licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4693
|
-
owner,
|
|
4694
|
-
licence.licenceType,
|
|
4695
|
-
now
|
|
4696
|
-
))
|
|
4697
|
-
);
|
|
4698
|
-
const highestVendorLicence = getHighestLicenceForCategory(
|
|
4699
|
-
effectiveVendorLicences,
|
|
4700
|
-
"vendor" /* VENDOR */
|
|
4701
|
-
);
|
|
4702
|
-
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR];
|
|
5179
|
+
return hasActiveProLicenceForResource({
|
|
5180
|
+
includeStripeProtected: true,
|
|
5181
|
+
resourceType: import_cluemart_shared36.EnumResourceType.VENDOR,
|
|
5182
|
+
userId: vendor.owner.userId
|
|
5183
|
+
});
|
|
4703
5184
|
}
|
|
4704
5185
|
|
|
4705
5186
|
// src/service/license/compliance/utils.ts
|
|
@@ -4709,12 +5190,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4709
5190
|
const pipeline = buildLicenceExpiryPipeline({
|
|
4710
5191
|
downgradeBranches: [
|
|
4711
5192
|
{
|
|
4712
|
-
case:
|
|
4713
|
-
then:
|
|
5193
|
+
case: import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
5194
|
+
then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
4714
5195
|
},
|
|
4715
5196
|
{
|
|
4716
|
-
case:
|
|
4717
|
-
then:
|
|
5197
|
+
case: import_cluemart_shared37.EnumUserLicence.PRO_VENDOR,
|
|
5198
|
+
then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
4718
5199
|
}
|
|
4719
5200
|
],
|
|
4720
5201
|
licenceTypes,
|
|
@@ -4843,7 +5324,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
|
4843
5324
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
4844
5325
|
|
|
4845
5326
|
// src/service/license/reminder/utils.ts
|
|
4846
|
-
var
|
|
5327
|
+
var import_cluemart_shared38 = require("@timardex/cluemart-shared");
|
|
4847
5328
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4848
5329
|
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4849
5330
|
|
|
@@ -4909,28 +5390,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
|
4909
5390
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4910
5391
|
}
|
|
4911
5392
|
function getLicenseName(licenceType) {
|
|
4912
|
-
return
|
|
5393
|
+
return import_cluemart_shared38.licenseNiceNames[licenceType] || licenceType;
|
|
4913
5394
|
}
|
|
4914
5395
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
4915
5396
|
if (isVendorLicense) {
|
|
4916
5397
|
return {
|
|
4917
|
-
notificationType:
|
|
4918
|
-
resourceType:
|
|
5398
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5399
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
4919
5400
|
};
|
|
4920
5401
|
}
|
|
4921
5402
|
if (isPartnerLicense) {
|
|
4922
5403
|
return {
|
|
4923
|
-
notificationType:
|
|
4924
|
-
resourceType:
|
|
5404
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5405
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
4925
5406
|
};
|
|
4926
5407
|
}
|
|
4927
5408
|
return {
|
|
4928
|
-
notificationType:
|
|
4929
|
-
resourceType:
|
|
5409
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5410
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
4930
5411
|
};
|
|
4931
5412
|
}
|
|
4932
5413
|
async function getLicenseResourceInfo(user, licence) {
|
|
4933
|
-
const isVendorLicense =
|
|
5414
|
+
const isVendorLicense = import_cluemart_shared38.vendorLicences.includes(licence.licenceType);
|
|
4934
5415
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
4935
5416
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4936
5417
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -4978,11 +5459,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
4978
5459
|
};
|
|
4979
5460
|
}
|
|
4980
5461
|
function getLicenceExpiryMode(licenceType) {
|
|
4981
|
-
return licenceType ===
|
|
5462
|
+
return licenceType === import_cluemart_shared38.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
4982
5463
|
}
|
|
4983
5464
|
async function sendLicenseReminder(user, licence) {
|
|
4984
5465
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4985
|
-
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(
|
|
5466
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared38.dateFormat);
|
|
4986
5467
|
const userId = String(user._id);
|
|
4987
5468
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4988
5469
|
if (!resourceInfo) {
|
|
@@ -5112,6 +5593,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5112
5593
|
REMINDER_WINDOW_MAX_HOURS,
|
|
5113
5594
|
REMINDER_WINDOW_MIN_HOURS,
|
|
5114
5595
|
SUBSCRIPTION_REWARD_TIMEZONE,
|
|
5596
|
+
acceptedAssociateUserIds,
|
|
5115
5597
|
activeAffiliateCodeExists,
|
|
5116
5598
|
awardAffiliateVendorSubscriptionRewards,
|
|
5117
5599
|
buildLicenceExpiryPipeline,
|
|
@@ -5125,6 +5607,9 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5125
5607
|
convertObjectIdsToStrings,
|
|
5126
5608
|
createLicenceObject,
|
|
5127
5609
|
dedupeArchivedSlotsByStartDateTime,
|
|
5610
|
+
detachAssociateGrantsForResources,
|
|
5611
|
+
detachStaleAssociateGrants,
|
|
5612
|
+
detachUsersFromResource,
|
|
5128
5613
|
didRemoveAnyEventDates,
|
|
5129
5614
|
didRemoveAnyStartedDates,
|
|
5130
5615
|
downgradeVendorProFeatures,
|
|
@@ -5134,6 +5619,8 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5134
5619
|
eventLicences,
|
|
5135
5620
|
findAffiliateByPromoCode,
|
|
5136
5621
|
findEventOrImportedMarketById,
|
|
5622
|
+
getActiveLicenceForResource,
|
|
5623
|
+
getAssociateAccessMeta,
|
|
5137
5624
|
getEventResourceInfo,
|
|
5138
5625
|
getHighestLicenceForCategory,
|
|
5139
5626
|
getLicenceCategory,
|
|
@@ -5143,11 +5630,17 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5143
5630
|
getPayingStripeSubscriptionPlan,
|
|
5144
5631
|
getPayingVendorStripeSubscriptionPlan,
|
|
5145
5632
|
getSubscriptionRewardPeriodBounds,
|
|
5633
|
+
getUserIdsWithActiveProLicence,
|
|
5146
5634
|
getVendorResourceInfo,
|
|
5635
|
+
grantAssociateGrants,
|
|
5147
5636
|
handleEventLicenceCompliance,
|
|
5148
5637
|
handlePartnerLicenceCompliance,
|
|
5149
5638
|
handleVendorLicenceCompliance,
|
|
5639
|
+
hasActiveProLicenceForResource,
|
|
5150
5640
|
hasValidLicence,
|
|
5641
|
+
isAssociableResourceType,
|
|
5642
|
+
isProLicence,
|
|
5643
|
+
isProtectedByCurrentStripeSubscription,
|
|
5151
5644
|
isStandardLicence,
|
|
5152
5645
|
isValidObjectId,
|
|
5153
5646
|
licenceCategoryMapping,
|
|
@@ -5162,6 +5655,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5162
5655
|
processUserCompliance,
|
|
5163
5656
|
processUserLicenseReminders,
|
|
5164
5657
|
publishNotificationEvents,
|
|
5658
|
+
reconcileAssociateGrants,
|
|
5165
5659
|
remindUsersAboutLicenseExpiration,
|
|
5166
5660
|
replaceUserLicenceWithObject,
|
|
5167
5661
|
restoreVendorProFeatures,
|