@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.
@@ -3160,10 +3160,13 @@ function convertObjectIdsToStrings(obj) {
3160
3160
 
3161
3161
  // src/service/event/updateAllEventDateTimeStatuses.ts
3162
3162
  var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3163
- var import_dayjs2 = __toESM(require("dayjs"));
3163
+ var import_dayjs3 = __toESM(require("dayjs"));
3164
3164
 
3165
3165
  // src/service/event/archiveEndedEventDates.ts
3166
3166
  var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3167
+ var import_dayjs2 = __toESM(require("dayjs"));
3168
+ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3169
+ import_dayjs2.default.extend(import_customParseFormat.default);
3167
3170
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3168
3171
  import_cluemart_shared26.EnumEventDateStatus.ENDED
3169
3172
  ]);
@@ -3190,6 +3193,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
3190
3193
  return true;
3191
3194
  });
3192
3195
  }
3196
+ function isPastCanceledEventDate(slot, now) {
3197
+ if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
3198
+ return false;
3199
+ }
3200
+ const endDateTime = (0, import_dayjs2.default)(
3201
+ `${slot.endDate} ${slot.endTime}`,
3202
+ `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
3203
+ true
3204
+ );
3205
+ return endDateTime.isValid() && endDateTime.isBefore(now);
3206
+ }
3193
3207
  async function persistArchivedEventDates(eventId, slots) {
3194
3208
  if (slots.length === 0) {
3195
3209
  return;
@@ -3254,7 +3268,11 @@ async function updateModelDateTimeStatuses(model, now) {
3254
3268
  }
3255
3269
  var ARCHIVABLE_EVENT_FILTER = {
3256
3270
  "dateTime.dateStatus": {
3257
- $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3271
+ $in: [
3272
+ import_cluemart_shared27.EnumEventDateStatus.ENDED,
3273
+ import_cluemart_shared27.EnumEventDateStatus.INVALID,
3274
+ import_cluemart_shared27.EnumEventDateStatus.CANCELED
3275
+ ]
3258
3276
  },
3259
3277
  deletedAt: null
3260
3278
  };
@@ -3269,7 +3287,9 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3269
3287
  archiveOps = [];
3270
3288
  }
3271
3289
  if (eventOps.length) {
3272
- await EventModel.bulkWrite(eventOps);
3290
+ await EventModel.bulkWrite(
3291
+ eventOps
3292
+ );
3273
3293
  eventOps = [];
3274
3294
  }
3275
3295
  };
@@ -3279,7 +3299,10 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3279
3299
  (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3280
3300
  );
3281
3301
  const { archive, discard } = splitEventDatesForArchive(updated);
3282
- if (archive.length === 0 && discard.length === 0) {
3302
+ const pastCanceled = updated.filter(
3303
+ (slot) => isPastCanceledEventDate(slot, now)
3304
+ );
3305
+ if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
3283
3306
  continue;
3284
3307
  }
3285
3308
  if (archive.length > 0) {
@@ -3293,16 +3316,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3293
3316
  });
3294
3317
  archivedCount += uniqueArchive.length;
3295
3318
  }
3319
+ const pullConditions = [];
3320
+ if (archive.length > 0 || discard.length > 0) {
3321
+ pullConditions.push({
3322
+ dateStatus: {
3323
+ $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3324
+ }
3325
+ });
3326
+ }
3327
+ for (const slot of pastCanceled) {
3328
+ pullConditions.push({
3329
+ dateStatus: import_cluemart_shared27.EnumEventDateStatus.CANCELED,
3330
+ startDate: slot.startDate,
3331
+ startTime: slot.startTime
3332
+ });
3333
+ }
3296
3334
  eventOps.push({
3297
3335
  updateOne: {
3298
3336
  filter: { _id: doc._id },
3299
3337
  update: {
3300
3338
  $pull: {
3301
- dateTime: {
3302
- dateStatus: {
3303
- $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3304
- }
3305
- }
3339
+ dateTime: { $or: pullConditions }
3306
3340
  }
3307
3341
  }
3308
3342
  }
@@ -3358,7 +3392,7 @@ async function cleanEventInfoDates(now) {
3358
3392
  return removedCount;
3359
3393
  }
3360
3394
  async function updateAllEventDateTimeStatuses() {
3361
- const now = (0, import_dayjs2.default)();
3395
+ const now = (0, import_dayjs3.default)();
3362
3396
  const [eventCount, marketCount] = await Promise.all([
3363
3397
  updateModelDateTimeStatuses(EventModel, now),
3364
3398
  updateModelDateTimeStatuses(
@@ -3422,11 +3456,11 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3422
3456
  }
3423
3457
 
3424
3458
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
3425
- var import_dayjs6 = __toESM(require("dayjs"));
3459
+ var import_dayjs7 = __toESM(require("dayjs"));
3426
3460
 
3427
3461
  // src/service/license/compliance/utils.ts
3428
3462
  var import_cluemart_shared33 = require("@timardex/cluemart-shared");
3429
- var import_dayjs5 = __toESM(require("dayjs"));
3463
+ var import_dayjs6 = __toESM(require("dayjs"));
3430
3464
 
3431
3465
  // src/service/license/compliance/event.ts
3432
3466
  var import_cluemart_shared29 = require("@timardex/cluemart-shared");
@@ -3658,11 +3692,11 @@ async function handlePartnerLicenceCompliance(user, now) {
3658
3692
 
3659
3693
  // src/service/license/compliance/vendor.ts
3660
3694
  var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3661
- var import_dayjs4 = __toESM(require("dayjs"));
3695
+ var import_dayjs5 = __toESM(require("dayjs"));
3662
3696
 
3663
3697
  // src/service/license/models.ts
3664
3698
  var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3665
- var import_dayjs3 = __toESM(require("dayjs"));
3699
+ var import_dayjs4 = __toESM(require("dayjs"));
3666
3700
  var import_graphql = require("graphql");
3667
3701
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3668
3702
  LicenceCategory2["EVENT"] = "event";
@@ -3743,7 +3777,7 @@ function getHighestLicenceForCategory(licences, category) {
3743
3777
  return highestLicence;
3744
3778
  }
3745
3779
  function createLicenceObject(expiryDate, licenceType) {
3746
- const today = (0, import_dayjs3.default)();
3780
+ const today = (0, import_dayjs4.default)();
3747
3781
  const expiryDateMapping = {
3748
3782
  [import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3749
3783
  [import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
@@ -4006,7 +4040,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4006
4040
  if (!stripe || stripe.currentPlan !== licenceType) {
4007
4041
  return false;
4008
4042
  }
4009
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs4.default)(stripe.paymentGracePeriodEndsAt) : null;
4043
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4010
4044
  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);
4011
4045
  if (hasActivePaymentGracePeriod) {
4012
4046
  return true;
@@ -4020,7 +4054,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4020
4054
  if (!stripe.endDate) {
4021
4055
  return false;
4022
4056
  }
4023
- const paidThrough = (0, import_dayjs4.default)(stripe.endDate);
4057
+ const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
4024
4058
  return paidThrough.isValid() && paidThrough.isAfter(now);
4025
4059
  }
4026
4060
  async function handleVendorLicenceCompliance(user, now) {
@@ -4037,7 +4071,7 @@ async function handleVendorLicenceCompliance(user, now) {
4037
4071
  (licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4038
4072
  );
4039
4073
  const expiredProLicences = proLicences.filter(
4040
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now)
4074
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4041
4075
  );
4042
4076
  const stripeProtectedLicenceTypes = new Set(
4043
4077
  expiredProLicences.filter(
@@ -4049,7 +4083,7 @@ async function handleVendorLicenceCompliance(user, now) {
4049
4083
  );
4050
4084
  const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
4051
4085
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4052
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4086
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4053
4087
  );
4054
4088
  if (!hasExpiredVendorLicence) {
4055
4089
  return;
@@ -4103,9 +4137,9 @@ async function vendorOwnerHasProLicence(vendorId) {
4103
4137
  if (!owner) {
4104
4138
  return false;
4105
4139
  }
4106
- const now = (0, import_dayjs4.default)();
4140
+ const now = (0, import_dayjs5.default)();
4107
4141
  const effectiveVendorLicences = owner.licences?.filter(
4108
- (licence) => licence?.licenceType && ((0, import_dayjs4.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4142
+ (licence) => licence?.licenceType && ((0, import_dayjs5.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4109
4143
  owner,
4110
4144
  licence.licenceType,
4111
4145
  now
@@ -4142,7 +4176,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4142
4176
  }
4143
4177
  function hasValidLicence(licences, licenceTypes, now) {
4144
4178
  return licences.some(
4145
- (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4179
+ (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
4146
4180
  );
4147
4181
  }
4148
4182
  async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
@@ -4169,7 +4203,7 @@ async function processUserCompliance(user, now) {
4169
4203
  }
4170
4204
 
4171
4205
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
4172
- async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs6.default)()) {
4206
+ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs7.default)()) {
4173
4207
  const user = await UserModel.findById(userId);
4174
4208
  if (!user) {
4175
4209
  return;
@@ -4177,7 +4211,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
4177
4211
  await processUserCompliance(user, now);
4178
4212
  }
4179
4213
  async function ensureUserLicenseCompliance() {
4180
- const now = (0, import_dayjs6.default)();
4214
+ const now = (0, import_dayjs7.default)();
4181
4215
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
4182
4216
  const nowDate = now.toDate();
4183
4217
  const users = await UserModel.find({
@@ -4252,7 +4286,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
4252
4286
  }
4253
4287
 
4254
4288
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4255
- var import_dayjs8 = __toESM(require("dayjs"));
4289
+ var import_dayjs9 = __toESM(require("dayjs"));
4256
4290
 
4257
4291
  // src/service/license/reminder/reminderWindow.ts
4258
4292
  var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
@@ -4261,7 +4295,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4261
4295
  // src/service/license/reminder/utils.ts
4262
4296
  var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4263
4297
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4264
- var import_dayjs7 = __toESM(require("dayjs"));
4298
+ var import_dayjs8 = __toESM(require("dayjs"));
4265
4299
 
4266
4300
  // src/service/license/reminder/vendor.ts
4267
4301
  async function getVendorResourceInfo(userId, vendorId) {
@@ -4320,7 +4354,7 @@ async function checkAndCreateNotification(payload) {
4320
4354
  }
4321
4355
  }
4322
4356
  function isLicenseExpiringIn7Days(expiryDate, now) {
4323
- const expiry = (0, import_dayjs7.default)(expiryDate);
4357
+ const expiry = (0, import_dayjs8.default)(expiryDate);
4324
4358
  const hoursUntilExpiry = expiry.diff(now, "hour", true);
4325
4359
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
4326
4360
  }
@@ -4398,7 +4432,7 @@ function getLicenceExpiryMode(licenceType) {
4398
4432
  }
4399
4433
  async function sendLicenseReminder(user, licence) {
4400
4434
  const licenceName = getLicenseName(licence.licenceType);
4401
- const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4435
+ const expiryDate = (0, import_dayjs8.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4402
4436
  const userId = String(user._id);
4403
4437
  const resourceInfo = await getLicenseResourceInfo(user, licence);
4404
4438
  if (!resourceInfo) {
@@ -4430,7 +4464,7 @@ async function sendLicenseReminder(user, licence) {
4430
4464
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
4431
4465
  }
4432
4466
  async function processLicenseReminder(licence, now) {
4433
- if ((0, import_dayjs7.default)(licence.expiryDate).isBefore(now)) {
4467
+ if ((0, import_dayjs8.default)(licence.expiryDate).isBefore(now)) {
4434
4468
  return false;
4435
4469
  }
4436
4470
  if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
@@ -4484,7 +4518,7 @@ async function processUserLicenseReminders(user, now) {
4484
4518
 
4485
4519
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4486
4520
  async function remindUsersAboutLicenseExpiration() {
4487
- const now = (0, import_dayjs8.default)();
4521
+ const now = (0, import_dayjs9.default)();
4488
4522
  console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
4489
4523
  const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
4490
4524
  const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();