@timardex/cluemart-server-shared 2.2.22 → 2.2.30
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-6AEy-gNx.d.mts → Affiliate-DIAzxxfs.d.mts} +2 -2
- package/dist/{Affiliate-D40kRxO_.d.ts → Affiliate-zioeZDyH.d.ts} +2 -2
- package/dist/{chunk-TIGQ6F5T.mjs → chunk-XGBC5DCX.mjs} +24 -3
- package/dist/chunk-XGBC5DCX.mjs.map +1 -0
- package/dist/index.cjs +243 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +104 -4
- package/dist/index.d.ts +104 -4
- package/dist/index.mjs +239 -27
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +22 -2
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +2 -2
- package/dist/mongoose/index.d.ts +2 -2
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +243 -27
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +103 -3
- package/dist/service/index.d.ts +103 -3
- package/dist/service/index.mjs +217 -26
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-TIGQ6F5T.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -82,6 +82,11 @@ __export(index_exports, {
|
|
|
82
82
|
baseResourceFields: () => baseResourceFields,
|
|
83
83
|
buildInitialBillingCatalogEntries: () => buildInitialBillingCatalogEntries,
|
|
84
84
|
buildLicenceExpiryPipeline: () => buildLicenceExpiryPipeline,
|
|
85
|
+
buildUserHasEnoughPointsFilter: () => buildUserHasEnoughPointsFilter,
|
|
86
|
+
buildUserPointAwardEntry: () => buildUserPointAwardEntry,
|
|
87
|
+
buildUserPointCreditFilter: () => buildUserPointCreditFilter,
|
|
88
|
+
buildUserPointDebitPipeline: () => buildUserPointDebitPipeline,
|
|
89
|
+
buildUserPointEntryRemovalPipeline: () => buildUserPointEntryRemovalPipeline,
|
|
85
90
|
checkOwnerHasLicence: () => checkOwnerHasLicence,
|
|
86
91
|
connectToDatabase: () => connectToDatabase,
|
|
87
92
|
convertObjectIdsToStrings: () => convertObjectIdsToStrings,
|
|
@@ -89,6 +94,7 @@ __export(index_exports, {
|
|
|
89
94
|
dateTimeSchema: () => dateTimeSchema,
|
|
90
95
|
dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
|
|
91
96
|
didRemoveAnyEventDates: () => didRemoveAnyEventDates,
|
|
97
|
+
didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
|
|
92
98
|
downgradeVendorProFeatures: () => downgradeVendorProFeatures,
|
|
93
99
|
ensureUserLicenseCompliance: () => ensureUserLicenseCompliance,
|
|
94
100
|
ensureUserLicenseComplianceForUser: () => ensureUserLicenseComplianceForUser,
|
|
@@ -1610,6 +1616,19 @@ var redeemedRewardSchema = new MongooseSchema12(
|
|
|
1610
1616
|
},
|
|
1611
1617
|
{ _id: false }
|
|
1612
1618
|
);
|
|
1619
|
+
var userOverallPointsSchema = new MongooseSchema12(
|
|
1620
|
+
{
|
|
1621
|
+
createdAt: { required: true, type: Date },
|
|
1622
|
+
points: { default: 0, required: true, type: Number },
|
|
1623
|
+
pointType: {
|
|
1624
|
+
enum: Object.values(import_cluemart_shared13.EnumPointType),
|
|
1625
|
+
required: true,
|
|
1626
|
+
type: String
|
|
1627
|
+
},
|
|
1628
|
+
sourceId: { required: false, type: String }
|
|
1629
|
+
},
|
|
1630
|
+
{ _id: false }
|
|
1631
|
+
);
|
|
1613
1632
|
var schema12 = new MongooseSchema12(
|
|
1614
1633
|
{
|
|
1615
1634
|
active: { default: false, required: true, type: Boolean },
|
|
@@ -1661,7 +1680,11 @@ var schema12 = new MongooseSchema12(
|
|
|
1661
1680
|
type: locationsSchema
|
|
1662
1681
|
},
|
|
1663
1682
|
nickName: { required: false, type: String },
|
|
1664
|
-
overallPoints: {
|
|
1683
|
+
overallPoints: {
|
|
1684
|
+
default: [],
|
|
1685
|
+
required: false,
|
|
1686
|
+
type: [userOverallPointsSchema]
|
|
1687
|
+
},
|
|
1665
1688
|
partner: {
|
|
1666
1689
|
ref: "Partner",
|
|
1667
1690
|
required: false,
|
|
@@ -2303,7 +2326,10 @@ var gameTypeSchema = new MongooseSchema24(
|
|
|
2303
2326
|
required: true,
|
|
2304
2327
|
type: String
|
|
2305
2328
|
},
|
|
2306
|
-
gameTypeId: { required: true, type: String }
|
|
2329
|
+
gameTypeId: { required: true, type: String },
|
|
2330
|
+
// See `GameType.pointsCredited`: absent means "completed before the marker
|
|
2331
|
+
// existed", which must not be re-credited.
|
|
2332
|
+
pointsCredited: { required: false, type: Boolean }
|
|
2307
2333
|
},
|
|
2308
2334
|
{ timestamps: true }
|
|
2309
2335
|
);
|
|
@@ -3251,15 +3277,189 @@ function convertObjectIdsToStrings(obj) {
|
|
|
3251
3277
|
return obj;
|
|
3252
3278
|
}
|
|
3253
3279
|
|
|
3280
|
+
// src/service/userPoints.ts
|
|
3281
|
+
var import_dayjs2 = __toESM(require("dayjs"));
|
|
3282
|
+
function assertValidPointAmount(amount, label) {
|
|
3283
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
3284
|
+
throw new RangeError(
|
|
3285
|
+
`Invalid user point ${label}: ${String(amount)}. Expected a finite, non-negative number.`
|
|
3286
|
+
);
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
function buildUserPointAwardEntry(pointType, points, sourceId) {
|
|
3290
|
+
assertValidPointAmount(points, "award");
|
|
3291
|
+
return {
|
|
3292
|
+
createdAt: (0, import_dayjs2.default)().toDate(),
|
|
3293
|
+
points,
|
|
3294
|
+
pointType,
|
|
3295
|
+
...sourceId === void 0 ? {} : { sourceId }
|
|
3296
|
+
};
|
|
3297
|
+
}
|
|
3298
|
+
function buildUserPointCreditFilter(userId, sourceId) {
|
|
3299
|
+
return {
|
|
3300
|
+
_id: userId,
|
|
3301
|
+
overallPoints: { $not: { $elemMatch: { sourceId } } }
|
|
3302
|
+
};
|
|
3303
|
+
}
|
|
3304
|
+
function buildUserHasEnoughPointsFilter(amount) {
|
|
3305
|
+
assertValidPointAmount(amount, "threshold");
|
|
3306
|
+
return {
|
|
3307
|
+
$expr: {
|
|
3308
|
+
$gte: [{ $sum: { $ifNull: ["$overallPoints.points", []] } }, amount]
|
|
3309
|
+
}
|
|
3310
|
+
};
|
|
3311
|
+
}
|
|
3312
|
+
function buildLedgerWriteExpr(computedLedger) {
|
|
3313
|
+
return {
|
|
3314
|
+
$cond: [
|
|
3315
|
+
{ $isArray: "$overallPoints" },
|
|
3316
|
+
computedLedger,
|
|
3317
|
+
{ $ifNull: ["$overallPoints", []] }
|
|
3318
|
+
]
|
|
3319
|
+
};
|
|
3320
|
+
}
|
|
3321
|
+
function buildUserPointDebitPipeline(amount) {
|
|
3322
|
+
assertValidPointAmount(amount, "debit");
|
|
3323
|
+
const debitedLedger = {
|
|
3324
|
+
$let: {
|
|
3325
|
+
vars: {
|
|
3326
|
+
sorted: {
|
|
3327
|
+
$sortArray: {
|
|
3328
|
+
input: { $ifNull: ["$overallPoints", []] },
|
|
3329
|
+
sortBy: { createdAt: 1 }
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
},
|
|
3333
|
+
in: {
|
|
3334
|
+
$let: {
|
|
3335
|
+
vars: {
|
|
3336
|
+
debited: {
|
|
3337
|
+
$reduce: {
|
|
3338
|
+
initialValue: { budget: amount, entries: [] },
|
|
3339
|
+
in: {
|
|
3340
|
+
$let: {
|
|
3341
|
+
vars: { available: { $ifNull: ["$$this.points", 0] } },
|
|
3342
|
+
in: {
|
|
3343
|
+
budget: {
|
|
3344
|
+
$subtract: [
|
|
3345
|
+
"$$value.budget",
|
|
3346
|
+
{ $min: ["$$available", "$$value.budget"] }
|
|
3347
|
+
]
|
|
3348
|
+
},
|
|
3349
|
+
entries: {
|
|
3350
|
+
$concatArrays: [
|
|
3351
|
+
"$$value.entries",
|
|
3352
|
+
[
|
|
3353
|
+
{
|
|
3354
|
+
$mergeObjects: [
|
|
3355
|
+
"$$this",
|
|
3356
|
+
{
|
|
3357
|
+
points: {
|
|
3358
|
+
$subtract: [
|
|
3359
|
+
"$$available",
|
|
3360
|
+
{
|
|
3361
|
+
$min: ["$$available", "$$value.budget"]
|
|
3362
|
+
}
|
|
3363
|
+
]
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
]
|
|
3367
|
+
}
|
|
3368
|
+
]
|
|
3369
|
+
]
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
},
|
|
3374
|
+
input: "$$sorted"
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
},
|
|
3378
|
+
in: {
|
|
3379
|
+
$filter: {
|
|
3380
|
+
as: "entry",
|
|
3381
|
+
cond: { $gt: ["$$entry.points", 0] },
|
|
3382
|
+
input: "$$debited.entries"
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
};
|
|
3389
|
+
return [
|
|
3390
|
+
{
|
|
3391
|
+
$set: {
|
|
3392
|
+
overallPoints: buildLedgerWriteExpr(debitedLedger)
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
];
|
|
3396
|
+
}
|
|
3397
|
+
function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
|
|
3398
|
+
const indexExpression = sourceId === void 0 ? { $indexOfArray: ["$$entries.pointType", pointType] } : {
|
|
3399
|
+
$indexOfArray: [
|
|
3400
|
+
{
|
|
3401
|
+
$map: {
|
|
3402
|
+
as: "entry",
|
|
3403
|
+
in: {
|
|
3404
|
+
$and: [
|
|
3405
|
+
{ $eq: ["$$entry.pointType", pointType] },
|
|
3406
|
+
{ $eq: ["$$entry.sourceId", sourceId] }
|
|
3407
|
+
]
|
|
3408
|
+
},
|
|
3409
|
+
input: "$$entries"
|
|
3410
|
+
}
|
|
3411
|
+
},
|
|
3412
|
+
true
|
|
3413
|
+
]
|
|
3414
|
+
};
|
|
3415
|
+
const entriesAfterRemoval = {
|
|
3416
|
+
$let: {
|
|
3417
|
+
vars: { entries: { $ifNull: ["$overallPoints", []] } },
|
|
3418
|
+
in: {
|
|
3419
|
+
$let: {
|
|
3420
|
+
vars: {
|
|
3421
|
+
index: indexExpression
|
|
3422
|
+
},
|
|
3423
|
+
in: {
|
|
3424
|
+
$cond: [
|
|
3425
|
+
{ $lt: ["$$index", 0] },
|
|
3426
|
+
"$$entries",
|
|
3427
|
+
{
|
|
3428
|
+
$concatArrays: [
|
|
3429
|
+
{ $slice: ["$$entries", "$$index"] },
|
|
3430
|
+
{
|
|
3431
|
+
$slice: [
|
|
3432
|
+
"$$entries",
|
|
3433
|
+
{ $add: ["$$index", 1] },
|
|
3434
|
+
{ $size: "$$entries" }
|
|
3435
|
+
]
|
|
3436
|
+
}
|
|
3437
|
+
]
|
|
3438
|
+
}
|
|
3439
|
+
]
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
};
|
|
3445
|
+
return [
|
|
3446
|
+
{
|
|
3447
|
+
$set: {
|
|
3448
|
+
overallPoints: buildLedgerWriteExpr(entriesAfterRemoval)
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
];
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3254
3454
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3255
3455
|
var import_cluemart_shared27 = require("@timardex/cluemart-shared");
|
|
3256
|
-
var
|
|
3456
|
+
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3257
3457
|
|
|
3258
3458
|
// src/service/event/archiveEndedEventDates.ts
|
|
3259
3459
|
var import_cluemart_shared26 = require("@timardex/cluemart-shared");
|
|
3260
|
-
var
|
|
3460
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3261
3461
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3262
|
-
|
|
3462
|
+
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
3263
3463
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3264
3464
|
import_cluemart_shared26.EnumEventDateStatus.ENDED
|
|
3265
3465
|
]);
|
|
@@ -3290,7 +3490,7 @@ function isPastCanceledEventDate(slot, now) {
|
|
|
3290
3490
|
if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
|
|
3291
3491
|
return false;
|
|
3292
3492
|
}
|
|
3293
|
-
const endDateTime = (0,
|
|
3493
|
+
const endDateTime = (0, import_dayjs3.default)(
|
|
3294
3494
|
`${slot.endDate} ${slot.endTime}`,
|
|
3295
3495
|
`${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
|
|
3296
3496
|
true
|
|
@@ -3485,7 +3685,7 @@ async function cleanEventInfoDates(now) {
|
|
|
3485
3685
|
return removedCount;
|
|
3486
3686
|
}
|
|
3487
3687
|
async function updateAllEventDateTimeStatuses() {
|
|
3488
|
-
const now = (0,
|
|
3688
|
+
const now = (0, import_dayjs4.default)();
|
|
3489
3689
|
const [eventCount, marketCount] = await Promise.all([
|
|
3490
3690
|
updateModelDateTimeStatuses(EventModel, now),
|
|
3491
3691
|
updateModelDateTimeStatuses(
|
|
@@ -3536,6 +3736,16 @@ function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
|
3536
3736
|
)
|
|
3537
3737
|
);
|
|
3538
3738
|
}
|
|
3739
|
+
function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
3740
|
+
if (!previousDateTime?.length) {
|
|
3741
|
+
return false;
|
|
3742
|
+
}
|
|
3743
|
+
return previousDateTime.some(
|
|
3744
|
+
(prev) => prev.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
3745
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED
|
|
3746
|
+
)
|
|
3747
|
+
);
|
|
3748
|
+
}
|
|
3539
3749
|
function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
3540
3750
|
return relationDates.map((relationDate) => {
|
|
3541
3751
|
const existsInEvent = eventDateTime?.some(
|
|
@@ -3549,11 +3759,11 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3549
3759
|
}
|
|
3550
3760
|
|
|
3551
3761
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
3552
|
-
var
|
|
3762
|
+
var import_dayjs8 = __toESM(require("dayjs"));
|
|
3553
3763
|
|
|
3554
3764
|
// src/service/license/compliance/utils.ts
|
|
3555
3765
|
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
3556
|
-
var
|
|
3766
|
+
var import_dayjs7 = __toESM(require("dayjs"));
|
|
3557
3767
|
|
|
3558
3768
|
// src/service/license/compliance/event.ts
|
|
3559
3769
|
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
@@ -3785,11 +3995,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
3785
3995
|
|
|
3786
3996
|
// src/service/license/compliance/vendor.ts
|
|
3787
3997
|
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3788
|
-
var
|
|
3998
|
+
var import_dayjs6 = __toESM(require("dayjs"));
|
|
3789
3999
|
|
|
3790
4000
|
// src/service/license/models.ts
|
|
3791
4001
|
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3792
|
-
var
|
|
4002
|
+
var import_dayjs5 = __toESM(require("dayjs"));
|
|
3793
4003
|
var import_graphql = require("graphql");
|
|
3794
4004
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
3795
4005
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -3870,7 +4080,7 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
3870
4080
|
return highestLicence;
|
|
3871
4081
|
}
|
|
3872
4082
|
function createLicenceObject(expiryDate, licenceType) {
|
|
3873
|
-
const today = (0,
|
|
4083
|
+
const today = (0, import_dayjs5.default)();
|
|
3874
4084
|
const expiryDateMapping = {
|
|
3875
4085
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
3876
4086
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
@@ -4133,7 +4343,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4133
4343
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4134
4344
|
return false;
|
|
4135
4345
|
}
|
|
4136
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0,
|
|
4346
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4137
4347
|
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);
|
|
4138
4348
|
if (hasActivePaymentGracePeriod) {
|
|
4139
4349
|
return true;
|
|
@@ -4147,7 +4357,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4147
4357
|
if (!stripe.endDate) {
|
|
4148
4358
|
return false;
|
|
4149
4359
|
}
|
|
4150
|
-
const paidThrough = (0,
|
|
4360
|
+
const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
|
|
4151
4361
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4152
4362
|
}
|
|
4153
4363
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -4164,7 +4374,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4164
4374
|
(licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
|
|
4165
4375
|
);
|
|
4166
4376
|
const expiredProLicences = proLicences.filter(
|
|
4167
|
-
(licence) => !(0,
|
|
4377
|
+
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4168
4378
|
);
|
|
4169
4379
|
const stripeProtectedLicenceTypes = new Set(
|
|
4170
4380
|
expiredProLicences.filter(
|
|
@@ -4176,7 +4386,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4176
4386
|
);
|
|
4177
4387
|
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
|
|
4178
4388
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4179
|
-
(licence) => !(0,
|
|
4389
|
+
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4180
4390
|
);
|
|
4181
4391
|
if (!hasExpiredVendorLicence) {
|
|
4182
4392
|
return;
|
|
@@ -4230,9 +4440,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4230
4440
|
if (!owner) {
|
|
4231
4441
|
return false;
|
|
4232
4442
|
}
|
|
4233
|
-
const now = (0,
|
|
4443
|
+
const now = (0, import_dayjs6.default)();
|
|
4234
4444
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
4235
|
-
(licence) => licence?.licenceType && ((0,
|
|
4445
|
+
(licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4236
4446
|
owner,
|
|
4237
4447
|
licence.licenceType,
|
|
4238
4448
|
now
|
|
@@ -4269,7 +4479,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4269
4479
|
}
|
|
4270
4480
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
4271
4481
|
return licences.some(
|
|
4272
|
-
(licence) => licenceTypes.includes(licence.licenceType) && (0,
|
|
4482
|
+
(licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs7.default)(licence.expiryDate).isAfter(now)
|
|
4273
4483
|
);
|
|
4274
4484
|
}
|
|
4275
4485
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -4296,7 +4506,7 @@ async function processUserCompliance(user, now) {
|
|
|
4296
4506
|
}
|
|
4297
4507
|
|
|
4298
4508
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
4299
|
-
async function ensureUserLicenseComplianceForUser(userId, now = (0,
|
|
4509
|
+
async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs8.default)()) {
|
|
4300
4510
|
const user = await UserModel.findById(userId);
|
|
4301
4511
|
if (!user) {
|
|
4302
4512
|
return;
|
|
@@ -4304,7 +4514,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
|
|
|
4304
4514
|
await processUserCompliance(user, now);
|
|
4305
4515
|
}
|
|
4306
4516
|
async function ensureUserLicenseCompliance() {
|
|
4307
|
-
const now = (0,
|
|
4517
|
+
const now = (0, import_dayjs8.default)();
|
|
4308
4518
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
4309
4519
|
const nowDate = now.toDate();
|
|
4310
4520
|
const users = await UserModel.find({
|
|
@@ -4379,7 +4589,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
4379
4589
|
}
|
|
4380
4590
|
|
|
4381
4591
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4382
|
-
var
|
|
4592
|
+
var import_dayjs10 = __toESM(require("dayjs"));
|
|
4383
4593
|
|
|
4384
4594
|
// src/service/license/reminder/reminderWindow.ts
|
|
4385
4595
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
@@ -4388,7 +4598,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
|
4388
4598
|
// src/service/license/reminder/utils.ts
|
|
4389
4599
|
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4390
4600
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4391
|
-
var
|
|
4601
|
+
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4392
4602
|
|
|
4393
4603
|
// src/service/license/reminder/vendor.ts
|
|
4394
4604
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -4447,7 +4657,7 @@ async function checkAndCreateNotification(payload) {
|
|
|
4447
4657
|
}
|
|
4448
4658
|
}
|
|
4449
4659
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
4450
|
-
const expiry = (0,
|
|
4660
|
+
const expiry = (0, import_dayjs9.default)(expiryDate);
|
|
4451
4661
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
4452
4662
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4453
4663
|
}
|
|
@@ -4525,7 +4735,7 @@ function getLicenceExpiryMode(licenceType) {
|
|
|
4525
4735
|
}
|
|
4526
4736
|
async function sendLicenseReminder(user, licence) {
|
|
4527
4737
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4528
|
-
const expiryDate = (0,
|
|
4738
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
|
|
4529
4739
|
const userId = String(user._id);
|
|
4530
4740
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4531
4741
|
if (!resourceInfo) {
|
|
@@ -4557,7 +4767,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
4557
4767
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
4558
4768
|
}
|
|
4559
4769
|
async function processLicenseReminder(licence, now) {
|
|
4560
|
-
if ((0,
|
|
4770
|
+
if ((0, import_dayjs9.default)(licence.expiryDate).isBefore(now)) {
|
|
4561
4771
|
return false;
|
|
4562
4772
|
}
|
|
4563
4773
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -4611,7 +4821,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
4611
4821
|
|
|
4612
4822
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4613
4823
|
async function remindUsersAboutLicenseExpiration() {
|
|
4614
|
-
const now = (0,
|
|
4824
|
+
const now = (0, import_dayjs10.default)();
|
|
4615
4825
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
4616
4826
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
4617
4827
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|
|
@@ -4702,6 +4912,11 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
4702
4912
|
baseResourceFields,
|
|
4703
4913
|
buildInitialBillingCatalogEntries,
|
|
4704
4914
|
buildLicenceExpiryPipeline,
|
|
4915
|
+
buildUserHasEnoughPointsFilter,
|
|
4916
|
+
buildUserPointAwardEntry,
|
|
4917
|
+
buildUserPointCreditFilter,
|
|
4918
|
+
buildUserPointDebitPipeline,
|
|
4919
|
+
buildUserPointEntryRemovalPipeline,
|
|
4705
4920
|
checkOwnerHasLicence,
|
|
4706
4921
|
connectToDatabase,
|
|
4707
4922
|
convertObjectIdsToStrings,
|
|
@@ -4709,6 +4924,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
4709
4924
|
dateTimeSchema,
|
|
4710
4925
|
dedupeArchivedSlotsByStartDateTime,
|
|
4711
4926
|
didRemoveAnyEventDates,
|
|
4927
|
+
didRemoveAnyStartedDates,
|
|
4712
4928
|
downgradeVendorProFeatures,
|
|
4713
4929
|
ensureUserLicenseCompliance,
|
|
4714
4930
|
ensureUserLicenseComplianceForUser,
|