@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 CHANGED
@@ -3253,10 +3253,13 @@ function convertObjectIdsToStrings(obj) {
3253
3253
 
3254
3254
  // src/service/event/updateAllEventDateTimeStatuses.ts
3255
3255
  var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3256
- var import_dayjs2 = __toESM(require("dayjs"));
3256
+ var import_dayjs3 = __toESM(require("dayjs"));
3257
3257
 
3258
3258
  // src/service/event/archiveEndedEventDates.ts
3259
3259
  var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3260
+ var import_dayjs2 = __toESM(require("dayjs"));
3261
+ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3262
+ import_dayjs2.default.extend(import_customParseFormat.default);
3260
3263
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3261
3264
  import_cluemart_shared26.EnumEventDateStatus.ENDED
3262
3265
  ]);
@@ -3283,6 +3286,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
3283
3286
  return true;
3284
3287
  });
3285
3288
  }
3289
+ function isPastCanceledEventDate(slot, now) {
3290
+ if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
3291
+ return false;
3292
+ }
3293
+ const endDateTime = (0, import_dayjs2.default)(
3294
+ `${slot.endDate} ${slot.endTime}`,
3295
+ `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
3296
+ true
3297
+ );
3298
+ return endDateTime.isValid() && endDateTime.isBefore(now);
3299
+ }
3286
3300
  async function persistArchivedEventDates(eventId, slots) {
3287
3301
  if (slots.length === 0) {
3288
3302
  return;
@@ -3347,7 +3361,11 @@ async function updateModelDateTimeStatuses(model, now) {
3347
3361
  }
3348
3362
  var ARCHIVABLE_EVENT_FILTER = {
3349
3363
  "dateTime.dateStatus": {
3350
- $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3364
+ $in: [
3365
+ import_cluemart_shared27.EnumEventDateStatus.ENDED,
3366
+ import_cluemart_shared27.EnumEventDateStatus.INVALID,
3367
+ import_cluemart_shared27.EnumEventDateStatus.CANCELED
3368
+ ]
3351
3369
  },
3352
3370
  deletedAt: null
3353
3371
  };
@@ -3362,7 +3380,9 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3362
3380
  archiveOps = [];
3363
3381
  }
3364
3382
  if (eventOps.length) {
3365
- await EventModel.bulkWrite(eventOps);
3383
+ await EventModel.bulkWrite(
3384
+ eventOps
3385
+ );
3366
3386
  eventOps = [];
3367
3387
  }
3368
3388
  };
@@ -3372,7 +3392,10 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3372
3392
  (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3373
3393
  );
3374
3394
  const { archive, discard } = splitEventDatesForArchive(updated);
3375
- if (archive.length === 0 && discard.length === 0) {
3395
+ const pastCanceled = updated.filter(
3396
+ (slot) => isPastCanceledEventDate(slot, now)
3397
+ );
3398
+ if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
3376
3399
  continue;
3377
3400
  }
3378
3401
  if (archive.length > 0) {
@@ -3386,16 +3409,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3386
3409
  });
3387
3410
  archivedCount += uniqueArchive.length;
3388
3411
  }
3412
+ const pullConditions = [];
3413
+ if (archive.length > 0 || discard.length > 0) {
3414
+ pullConditions.push({
3415
+ dateStatus: {
3416
+ $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3417
+ }
3418
+ });
3419
+ }
3420
+ for (const slot of pastCanceled) {
3421
+ pullConditions.push({
3422
+ dateStatus: import_cluemart_shared27.EnumEventDateStatus.CANCELED,
3423
+ startDate: slot.startDate,
3424
+ startTime: slot.startTime
3425
+ });
3426
+ }
3389
3427
  eventOps.push({
3390
3428
  updateOne: {
3391
3429
  filter: { _id: doc._id },
3392
3430
  update: {
3393
3431
  $pull: {
3394
- dateTime: {
3395
- dateStatus: {
3396
- $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3397
- }
3398
- }
3432
+ dateTime: { $or: pullConditions }
3399
3433
  }
3400
3434
  }
3401
3435
  }
@@ -3451,7 +3485,7 @@ async function cleanEventInfoDates(now) {
3451
3485
  return removedCount;
3452
3486
  }
3453
3487
  async function updateAllEventDateTimeStatuses() {
3454
- const now = (0, import_dayjs2.default)();
3488
+ const now = (0, import_dayjs3.default)();
3455
3489
  const [eventCount, marketCount] = await Promise.all([
3456
3490
  updateModelDateTimeStatuses(EventModel, now),
3457
3491
  updateModelDateTimeStatuses(
@@ -3515,11 +3549,11 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3515
3549
  }
3516
3550
 
3517
3551
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
3518
- var import_dayjs6 = __toESM(require("dayjs"));
3552
+ var import_dayjs7 = __toESM(require("dayjs"));
3519
3553
 
3520
3554
  // src/service/license/compliance/utils.ts
3521
3555
  var import_cluemart_shared33 = require("@timardex/cluemart-shared");
3522
- var import_dayjs5 = __toESM(require("dayjs"));
3556
+ var import_dayjs6 = __toESM(require("dayjs"));
3523
3557
 
3524
3558
  // src/service/license/compliance/event.ts
3525
3559
  var import_cluemart_shared29 = require("@timardex/cluemart-shared");
@@ -3751,11 +3785,11 @@ async function handlePartnerLicenceCompliance(user, now) {
3751
3785
 
3752
3786
  // src/service/license/compliance/vendor.ts
3753
3787
  var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3754
- var import_dayjs4 = __toESM(require("dayjs"));
3788
+ var import_dayjs5 = __toESM(require("dayjs"));
3755
3789
 
3756
3790
  // src/service/license/models.ts
3757
3791
  var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3758
- var import_dayjs3 = __toESM(require("dayjs"));
3792
+ var import_dayjs4 = __toESM(require("dayjs"));
3759
3793
  var import_graphql = require("graphql");
3760
3794
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3761
3795
  LicenceCategory2["EVENT"] = "event";
@@ -3836,7 +3870,7 @@ function getHighestLicenceForCategory(licences, category) {
3836
3870
  return highestLicence;
3837
3871
  }
3838
3872
  function createLicenceObject(expiryDate, licenceType) {
3839
- const today = (0, import_dayjs3.default)();
3873
+ const today = (0, import_dayjs4.default)();
3840
3874
  const expiryDateMapping = {
3841
3875
  [import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3842
3876
  [import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
@@ -4099,7 +4133,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4099
4133
  if (!stripe || stripe.currentPlan !== licenceType) {
4100
4134
  return false;
4101
4135
  }
4102
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs4.default)(stripe.paymentGracePeriodEndsAt) : null;
4136
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4103
4137
  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);
4104
4138
  if (hasActivePaymentGracePeriod) {
4105
4139
  return true;
@@ -4113,7 +4147,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4113
4147
  if (!stripe.endDate) {
4114
4148
  return false;
4115
4149
  }
4116
- const paidThrough = (0, import_dayjs4.default)(stripe.endDate);
4150
+ const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
4117
4151
  return paidThrough.isValid() && paidThrough.isAfter(now);
4118
4152
  }
4119
4153
  async function handleVendorLicenceCompliance(user, now) {
@@ -4130,7 +4164,7 @@ async function handleVendorLicenceCompliance(user, now) {
4130
4164
  (licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4131
4165
  );
4132
4166
  const expiredProLicences = proLicences.filter(
4133
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now)
4167
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4134
4168
  );
4135
4169
  const stripeProtectedLicenceTypes = new Set(
4136
4170
  expiredProLicences.filter(
@@ -4142,7 +4176,7 @@ async function handleVendorLicenceCompliance(user, now) {
4142
4176
  );
4143
4177
  const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
4144
4178
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4145
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4179
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4146
4180
  );
4147
4181
  if (!hasExpiredVendorLicence) {
4148
4182
  return;
@@ -4196,9 +4230,9 @@ async function vendorOwnerHasProLicence(vendorId) {
4196
4230
  if (!owner) {
4197
4231
  return false;
4198
4232
  }
4199
- const now = (0, import_dayjs4.default)();
4233
+ const now = (0, import_dayjs5.default)();
4200
4234
  const effectiveVendorLicences = owner.licences?.filter(
4201
- (licence) => licence?.licenceType && ((0, import_dayjs4.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4235
+ (licence) => licence?.licenceType && ((0, import_dayjs5.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4202
4236
  owner,
4203
4237
  licence.licenceType,
4204
4238
  now
@@ -4235,7 +4269,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4235
4269
  }
4236
4270
  function hasValidLicence(licences, licenceTypes, now) {
4237
4271
  return licences.some(
4238
- (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4272
+ (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
4239
4273
  );
4240
4274
  }
4241
4275
  async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
@@ -4262,7 +4296,7 @@ async function processUserCompliance(user, now) {
4262
4296
  }
4263
4297
 
4264
4298
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
4265
- async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs6.default)()) {
4299
+ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs7.default)()) {
4266
4300
  const user = await UserModel.findById(userId);
4267
4301
  if (!user) {
4268
4302
  return;
@@ -4270,7 +4304,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
4270
4304
  await processUserCompliance(user, now);
4271
4305
  }
4272
4306
  async function ensureUserLicenseCompliance() {
4273
- const now = (0, import_dayjs6.default)();
4307
+ const now = (0, import_dayjs7.default)();
4274
4308
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
4275
4309
  const nowDate = now.toDate();
4276
4310
  const users = await UserModel.find({
@@ -4345,7 +4379,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
4345
4379
  }
4346
4380
 
4347
4381
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4348
- var import_dayjs8 = __toESM(require("dayjs"));
4382
+ var import_dayjs9 = __toESM(require("dayjs"));
4349
4383
 
4350
4384
  // src/service/license/reminder/reminderWindow.ts
4351
4385
  var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
@@ -4354,7 +4388,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4354
4388
  // src/service/license/reminder/utils.ts
4355
4389
  var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4356
4390
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4357
- var import_dayjs7 = __toESM(require("dayjs"));
4391
+ var import_dayjs8 = __toESM(require("dayjs"));
4358
4392
 
4359
4393
  // src/service/license/reminder/vendor.ts
4360
4394
  async function getVendorResourceInfo(userId, vendorId) {
@@ -4413,7 +4447,7 @@ async function checkAndCreateNotification(payload) {
4413
4447
  }
4414
4448
  }
4415
4449
  function isLicenseExpiringIn7Days(expiryDate, now) {
4416
- const expiry = (0, import_dayjs7.default)(expiryDate);
4450
+ const expiry = (0, import_dayjs8.default)(expiryDate);
4417
4451
  const hoursUntilExpiry = expiry.diff(now, "hour", true);
4418
4452
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
4419
4453
  }
@@ -4491,7 +4525,7 @@ function getLicenceExpiryMode(licenceType) {
4491
4525
  }
4492
4526
  async function sendLicenseReminder(user, licence) {
4493
4527
  const licenceName = getLicenseName(licence.licenceType);
4494
- const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4528
+ const expiryDate = (0, import_dayjs8.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4495
4529
  const userId = String(user._id);
4496
4530
  const resourceInfo = await getLicenseResourceInfo(user, licence);
4497
4531
  if (!resourceInfo) {
@@ -4523,7 +4557,7 @@ async function sendLicenseReminder(user, licence) {
4523
4557
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
4524
4558
  }
4525
4559
  async function processLicenseReminder(licence, now) {
4526
- if ((0, import_dayjs7.default)(licence.expiryDate).isBefore(now)) {
4560
+ if ((0, import_dayjs8.default)(licence.expiryDate).isBefore(now)) {
4527
4561
  return false;
4528
4562
  }
4529
4563
  if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
@@ -4577,7 +4611,7 @@ async function processUserLicenseReminders(user, now) {
4577
4611
 
4578
4612
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4579
4613
  async function remindUsersAboutLicenseExpiration() {
4580
- const now = (0, import_dayjs8.default)();
4614
+ const now = (0, import_dayjs9.default)();
4581
4615
  console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
4582
4616
  const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
4583
4617
  const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();