@timardex/cluemart-server-shared 2.2.21 → 2.2.22
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/index.cjs +64 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +70 -32
- package/dist/index.mjs.map +1 -1
- package/dist/service/index.cjs +64 -30
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.mjs +70 -32
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3192,10 +3192,17 @@ import {
|
|
|
3192
3192
|
filterDatesByFutureStatus,
|
|
3193
3193
|
updateSingleDateTimeStatus
|
|
3194
3194
|
} from "@timardex/cluemart-shared";
|
|
3195
|
-
import
|
|
3195
|
+
import dayjs3 from "dayjs";
|
|
3196
3196
|
|
|
3197
3197
|
// src/service/event/archiveEndedEventDates.ts
|
|
3198
|
-
import {
|
|
3198
|
+
import {
|
|
3199
|
+
EnumEventDateStatus as EnumEventDateStatus6,
|
|
3200
|
+
dateFormat,
|
|
3201
|
+
timeFormat
|
|
3202
|
+
} from "@timardex/cluemart-shared";
|
|
3203
|
+
import dayjs2 from "dayjs";
|
|
3204
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
3205
|
+
dayjs2.extend(customParseFormat);
|
|
3199
3206
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3200
3207
|
EnumEventDateStatus6.ENDED
|
|
3201
3208
|
]);
|
|
@@ -3222,6 +3229,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
|
3222
3229
|
return true;
|
|
3223
3230
|
});
|
|
3224
3231
|
}
|
|
3232
|
+
function isPastCanceledEventDate(slot, now) {
|
|
3233
|
+
if (slot.dateStatus !== EnumEventDateStatus6.CANCELED) {
|
|
3234
|
+
return false;
|
|
3235
|
+
}
|
|
3236
|
+
const endDateTime = dayjs2(
|
|
3237
|
+
`${slot.endDate} ${slot.endTime}`,
|
|
3238
|
+
`${dateFormat} ${timeFormat}`,
|
|
3239
|
+
true
|
|
3240
|
+
);
|
|
3241
|
+
return endDateTime.isValid() && endDateTime.isBefore(now);
|
|
3242
|
+
}
|
|
3225
3243
|
async function persistArchivedEventDates(eventId, slots) {
|
|
3226
3244
|
if (slots.length === 0) {
|
|
3227
3245
|
return;
|
|
@@ -3286,7 +3304,11 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3286
3304
|
}
|
|
3287
3305
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
3288
3306
|
"dateTime.dateStatus": {
|
|
3289
|
-
$in: [
|
|
3307
|
+
$in: [
|
|
3308
|
+
EnumEventDateStatus7.ENDED,
|
|
3309
|
+
EnumEventDateStatus7.INVALID,
|
|
3310
|
+
EnumEventDateStatus7.CANCELED
|
|
3311
|
+
]
|
|
3290
3312
|
},
|
|
3291
3313
|
deletedAt: null
|
|
3292
3314
|
};
|
|
@@ -3301,7 +3323,9 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3301
3323
|
archiveOps = [];
|
|
3302
3324
|
}
|
|
3303
3325
|
if (eventOps.length) {
|
|
3304
|
-
await EventModel.bulkWrite(
|
|
3326
|
+
await EventModel.bulkWrite(
|
|
3327
|
+
eventOps
|
|
3328
|
+
);
|
|
3305
3329
|
eventOps = [];
|
|
3306
3330
|
}
|
|
3307
3331
|
};
|
|
@@ -3311,7 +3335,10 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3311
3335
|
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
3312
3336
|
);
|
|
3313
3337
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3314
|
-
|
|
3338
|
+
const pastCanceled = updated.filter(
|
|
3339
|
+
(slot) => isPastCanceledEventDate(slot, now)
|
|
3340
|
+
);
|
|
3341
|
+
if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
|
|
3315
3342
|
continue;
|
|
3316
3343
|
}
|
|
3317
3344
|
if (archive.length > 0) {
|
|
@@ -3325,16 +3352,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3325
3352
|
});
|
|
3326
3353
|
archivedCount += uniqueArchive.length;
|
|
3327
3354
|
}
|
|
3355
|
+
const pullConditions = [];
|
|
3356
|
+
if (archive.length > 0 || discard.length > 0) {
|
|
3357
|
+
pullConditions.push({
|
|
3358
|
+
dateStatus: {
|
|
3359
|
+
$in: [EnumEventDateStatus7.ENDED, EnumEventDateStatus7.INVALID]
|
|
3360
|
+
}
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3363
|
+
for (const slot of pastCanceled) {
|
|
3364
|
+
pullConditions.push({
|
|
3365
|
+
dateStatus: EnumEventDateStatus7.CANCELED,
|
|
3366
|
+
startDate: slot.startDate,
|
|
3367
|
+
startTime: slot.startTime
|
|
3368
|
+
});
|
|
3369
|
+
}
|
|
3328
3370
|
eventOps.push({
|
|
3329
3371
|
updateOne: {
|
|
3330
3372
|
filter: { _id: doc._id },
|
|
3331
3373
|
update: {
|
|
3332
3374
|
$pull: {
|
|
3333
|
-
dateTime: {
|
|
3334
|
-
dateStatus: {
|
|
3335
|
-
$in: [EnumEventDateStatus7.ENDED, EnumEventDateStatus7.INVALID]
|
|
3336
|
-
}
|
|
3337
|
-
}
|
|
3375
|
+
dateTime: { $or: pullConditions }
|
|
3338
3376
|
}
|
|
3339
3377
|
}
|
|
3340
3378
|
}
|
|
@@ -3390,7 +3428,7 @@ async function cleanEventInfoDates(now) {
|
|
|
3390
3428
|
return removedCount;
|
|
3391
3429
|
}
|
|
3392
3430
|
async function updateAllEventDateTimeStatuses() {
|
|
3393
|
-
const now =
|
|
3431
|
+
const now = dayjs3();
|
|
3394
3432
|
const [eventCount, marketCount] = await Promise.all([
|
|
3395
3433
|
updateModelDateTimeStatuses(EventModel, now),
|
|
3396
3434
|
updateModelDateTimeStatuses(
|
|
@@ -3456,13 +3494,13 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3456
3494
|
}
|
|
3457
3495
|
|
|
3458
3496
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
3459
|
-
import
|
|
3497
|
+
import dayjs7 from "dayjs";
|
|
3460
3498
|
|
|
3461
3499
|
// src/service/license/compliance/utils.ts
|
|
3462
3500
|
import {
|
|
3463
3501
|
EnumUserLicence as EnumUserLicence10
|
|
3464
3502
|
} from "@timardex/cluemart-shared";
|
|
3465
|
-
import
|
|
3503
|
+
import dayjs6 from "dayjs";
|
|
3466
3504
|
|
|
3467
3505
|
// src/service/license/compliance/event.ts
|
|
3468
3506
|
import { EnumUserLicence as EnumUserLicence6 } from "@timardex/cluemart-shared";
|
|
@@ -3700,7 +3738,7 @@ import {
|
|
|
3700
3738
|
EnumUserLicence as EnumUserLicence9,
|
|
3701
3739
|
vendorLicences
|
|
3702
3740
|
} from "@timardex/cluemart-shared";
|
|
3703
|
-
import
|
|
3741
|
+
import dayjs5 from "dayjs";
|
|
3704
3742
|
|
|
3705
3743
|
// src/service/license/models.ts
|
|
3706
3744
|
import {
|
|
@@ -3709,7 +3747,7 @@ import {
|
|
|
3709
3747
|
isNonVisitorResourceType,
|
|
3710
3748
|
LicenceExpiryDate
|
|
3711
3749
|
} from "@timardex/cluemart-shared";
|
|
3712
|
-
import
|
|
3750
|
+
import dayjs4 from "dayjs";
|
|
3713
3751
|
import { GraphQLError } from "graphql";
|
|
3714
3752
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
3715
3753
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -3790,7 +3828,7 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
3790
3828
|
return highestLicence;
|
|
3791
3829
|
}
|
|
3792
3830
|
function createLicenceObject(expiryDate, licenceType) {
|
|
3793
|
-
const today =
|
|
3831
|
+
const today = dayjs4();
|
|
3794
3832
|
const expiryDateMapping = {
|
|
3795
3833
|
[LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
3796
3834
|
[LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
@@ -4053,7 +4091,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4053
4091
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4054
4092
|
return false;
|
|
4055
4093
|
}
|
|
4056
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ?
|
|
4094
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs5(stripe.paymentGracePeriodEndsAt) : null;
|
|
4057
4095
|
const hasActivePaymentGracePeriod = (stripe.status === EnumSubscriptionStatus3.PAST_DUE || stripe.status === EnumSubscriptionStatus3.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
4058
4096
|
if (hasActivePaymentGracePeriod) {
|
|
4059
4097
|
return true;
|
|
@@ -4067,7 +4105,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4067
4105
|
if (!stripe.endDate) {
|
|
4068
4106
|
return false;
|
|
4069
4107
|
}
|
|
4070
|
-
const paidThrough =
|
|
4108
|
+
const paidThrough = dayjs5(stripe.endDate);
|
|
4071
4109
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4072
4110
|
}
|
|
4073
4111
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -4084,7 +4122,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4084
4122
|
(licence) => licence.licenceType !== EnumUserLicence9.STANDARD_VENDOR
|
|
4085
4123
|
);
|
|
4086
4124
|
const expiredProLicences = proLicences.filter(
|
|
4087
|
-
(licence) => !
|
|
4125
|
+
(licence) => !dayjs5(licence.expiryDate).isAfter(now)
|
|
4088
4126
|
);
|
|
4089
4127
|
const stripeProtectedLicenceTypes = new Set(
|
|
4090
4128
|
expiredProLicences.filter(
|
|
@@ -4096,7 +4134,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4096
4134
|
);
|
|
4097
4135
|
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, vendorLicences, now);
|
|
4098
4136
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4099
|
-
(licence) => !
|
|
4137
|
+
(licence) => !dayjs5(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4100
4138
|
);
|
|
4101
4139
|
if (!hasExpiredVendorLicence) {
|
|
4102
4140
|
return;
|
|
@@ -4150,9 +4188,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4150
4188
|
if (!owner) {
|
|
4151
4189
|
return false;
|
|
4152
4190
|
}
|
|
4153
|
-
const now =
|
|
4191
|
+
const now = dayjs5();
|
|
4154
4192
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
4155
|
-
(licence) => licence?.licenceType && (
|
|
4193
|
+
(licence) => licence?.licenceType && (dayjs5(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4156
4194
|
owner,
|
|
4157
4195
|
licence.licenceType,
|
|
4158
4196
|
now
|
|
@@ -4189,7 +4227,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4189
4227
|
}
|
|
4190
4228
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
4191
4229
|
return licences.some(
|
|
4192
|
-
(licence) => licenceTypes.includes(licence.licenceType) &&
|
|
4230
|
+
(licence) => licenceTypes.includes(licence.licenceType) && dayjs6(licence.expiryDate).isAfter(now)
|
|
4193
4231
|
);
|
|
4194
4232
|
}
|
|
4195
4233
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -4216,7 +4254,7 @@ async function processUserCompliance(user, now) {
|
|
|
4216
4254
|
}
|
|
4217
4255
|
|
|
4218
4256
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
4219
|
-
async function ensureUserLicenseComplianceForUser(userId, now =
|
|
4257
|
+
async function ensureUserLicenseComplianceForUser(userId, now = dayjs7()) {
|
|
4220
4258
|
const user = await UserModel.findById(userId);
|
|
4221
4259
|
if (!user) {
|
|
4222
4260
|
return;
|
|
@@ -4224,7 +4262,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = dayjs6()) {
|
|
|
4224
4262
|
await processUserCompliance(user, now);
|
|
4225
4263
|
}
|
|
4226
4264
|
async function ensureUserLicenseCompliance() {
|
|
4227
|
-
const now =
|
|
4265
|
+
const now = dayjs7();
|
|
4228
4266
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
4229
4267
|
const nowDate = now.toDate();
|
|
4230
4268
|
const users = await UserModel.find({
|
|
@@ -4299,7 +4337,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
4299
4337
|
}
|
|
4300
4338
|
|
|
4301
4339
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4302
|
-
import
|
|
4340
|
+
import dayjs9 from "dayjs";
|
|
4303
4341
|
|
|
4304
4342
|
// src/service/license/reminder/reminderWindow.ts
|
|
4305
4343
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
@@ -4307,7 +4345,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
|
4307
4345
|
|
|
4308
4346
|
// src/service/license/reminder/utils.ts
|
|
4309
4347
|
import {
|
|
4310
|
-
dateFormat,
|
|
4348
|
+
dateFormat as dateFormat2,
|
|
4311
4349
|
EnumNotificationResourceType as EnumNotificationResourceType6,
|
|
4312
4350
|
EnumNotificationType as EnumNotificationType5,
|
|
4313
4351
|
EnumUserLicence as EnumUserLicence11,
|
|
@@ -4315,7 +4353,7 @@ import {
|
|
|
4315
4353
|
vendorLicences as vendorLicences2
|
|
4316
4354
|
} from "@timardex/cluemart-shared";
|
|
4317
4355
|
import { formatDate } from "@timardex/cluemart-shared/utils";
|
|
4318
|
-
import
|
|
4356
|
+
import dayjs8 from "dayjs";
|
|
4319
4357
|
|
|
4320
4358
|
// src/service/license/reminder/vendor.ts
|
|
4321
4359
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -4374,7 +4412,7 @@ async function checkAndCreateNotification(payload) {
|
|
|
4374
4412
|
}
|
|
4375
4413
|
}
|
|
4376
4414
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
4377
|
-
const expiry =
|
|
4415
|
+
const expiry = dayjs8(expiryDate);
|
|
4378
4416
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
4379
4417
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4380
4418
|
}
|
|
@@ -4452,7 +4490,7 @@ function getLicenceExpiryMode(licenceType) {
|
|
|
4452
4490
|
}
|
|
4453
4491
|
async function sendLicenseReminder(user, licence) {
|
|
4454
4492
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4455
|
-
const expiryDate =
|
|
4493
|
+
const expiryDate = dayjs8(licence.expiryDate).format(dateFormat2);
|
|
4456
4494
|
const userId = String(user._id);
|
|
4457
4495
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4458
4496
|
if (!resourceInfo) {
|
|
@@ -4484,7 +4522,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
4484
4522
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
4485
4523
|
}
|
|
4486
4524
|
async function processLicenseReminder(licence, now) {
|
|
4487
|
-
if (
|
|
4525
|
+
if (dayjs8(licence.expiryDate).isBefore(now)) {
|
|
4488
4526
|
return false;
|
|
4489
4527
|
}
|
|
4490
4528
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -4538,7 +4576,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
4538
4576
|
|
|
4539
4577
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4540
4578
|
async function remindUsersAboutLicenseExpiration() {
|
|
4541
|
-
const now =
|
|
4579
|
+
const now = dayjs9();
|
|
4542
4580
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
4543
4581
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
4544
4582
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|