@timardex/cluemart-server-shared 2.2.21 → 2.2.23

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.
@@ -44,6 +44,7 @@ __export(service_exports, {
44
44
  createLicenceObject: () => createLicenceObject,
45
45
  dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
46
46
  didRemoveAnyEventDates: () => didRemoveAnyEventDates,
47
+ didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
47
48
  downgradeVendorProFeatures: () => downgradeVendorProFeatures,
48
49
  ensureUserLicenseCompliance: () => ensureUserLicenseCompliance,
49
50
  ensureUserLicenseComplianceForUser: () => ensureUserLicenseComplianceForUser,
@@ -3160,10 +3161,13 @@ function convertObjectIdsToStrings(obj) {
3160
3161
 
3161
3162
  // src/service/event/updateAllEventDateTimeStatuses.ts
3162
3163
  var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3163
- var import_dayjs2 = __toESM(require("dayjs"));
3164
+ var import_dayjs3 = __toESM(require("dayjs"));
3164
3165
 
3165
3166
  // src/service/event/archiveEndedEventDates.ts
3166
3167
  var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3168
+ var import_dayjs2 = __toESM(require("dayjs"));
3169
+ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3170
+ import_dayjs2.default.extend(import_customParseFormat.default);
3167
3171
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3168
3172
  import_cluemart_shared26.EnumEventDateStatus.ENDED
3169
3173
  ]);
@@ -3190,6 +3194,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
3190
3194
  return true;
3191
3195
  });
3192
3196
  }
3197
+ function isPastCanceledEventDate(slot, now) {
3198
+ if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
3199
+ return false;
3200
+ }
3201
+ const endDateTime = (0, import_dayjs2.default)(
3202
+ `${slot.endDate} ${slot.endTime}`,
3203
+ `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
3204
+ true
3205
+ );
3206
+ return endDateTime.isValid() && endDateTime.isBefore(now);
3207
+ }
3193
3208
  async function persistArchivedEventDates(eventId, slots) {
3194
3209
  if (slots.length === 0) {
3195
3210
  return;
@@ -3254,7 +3269,11 @@ async function updateModelDateTimeStatuses(model, now) {
3254
3269
  }
3255
3270
  var ARCHIVABLE_EVENT_FILTER = {
3256
3271
  "dateTime.dateStatus": {
3257
- $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3272
+ $in: [
3273
+ import_cluemart_shared27.EnumEventDateStatus.ENDED,
3274
+ import_cluemart_shared27.EnumEventDateStatus.INVALID,
3275
+ import_cluemart_shared27.EnumEventDateStatus.CANCELED
3276
+ ]
3258
3277
  },
3259
3278
  deletedAt: null
3260
3279
  };
@@ -3269,7 +3288,9 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3269
3288
  archiveOps = [];
3270
3289
  }
3271
3290
  if (eventOps.length) {
3272
- await EventModel.bulkWrite(eventOps);
3291
+ await EventModel.bulkWrite(
3292
+ eventOps
3293
+ );
3273
3294
  eventOps = [];
3274
3295
  }
3275
3296
  };
@@ -3279,7 +3300,10 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3279
3300
  (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3280
3301
  );
3281
3302
  const { archive, discard } = splitEventDatesForArchive(updated);
3282
- if (archive.length === 0 && discard.length === 0) {
3303
+ const pastCanceled = updated.filter(
3304
+ (slot) => isPastCanceledEventDate(slot, now)
3305
+ );
3306
+ if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
3283
3307
  continue;
3284
3308
  }
3285
3309
  if (archive.length > 0) {
@@ -3293,16 +3317,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3293
3317
  });
3294
3318
  archivedCount += uniqueArchive.length;
3295
3319
  }
3320
+ const pullConditions = [];
3321
+ if (archive.length > 0 || discard.length > 0) {
3322
+ pullConditions.push({
3323
+ dateStatus: {
3324
+ $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3325
+ }
3326
+ });
3327
+ }
3328
+ for (const slot of pastCanceled) {
3329
+ pullConditions.push({
3330
+ dateStatus: import_cluemart_shared27.EnumEventDateStatus.CANCELED,
3331
+ startDate: slot.startDate,
3332
+ startTime: slot.startTime
3333
+ });
3334
+ }
3296
3335
  eventOps.push({
3297
3336
  updateOne: {
3298
3337
  filter: { _id: doc._id },
3299
3338
  update: {
3300
3339
  $pull: {
3301
- dateTime: {
3302
- dateStatus: {
3303
- $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3304
- }
3305
- }
3340
+ dateTime: { $or: pullConditions }
3306
3341
  }
3307
3342
  }
3308
3343
  }
@@ -3358,7 +3393,7 @@ async function cleanEventInfoDates(now) {
3358
3393
  return removedCount;
3359
3394
  }
3360
3395
  async function updateAllEventDateTimeStatuses() {
3361
- const now = (0, import_dayjs2.default)();
3396
+ const now = (0, import_dayjs3.default)();
3362
3397
  const [eventCount, marketCount] = await Promise.all([
3363
3398
  updateModelDateTimeStatuses(EventModel, now),
3364
3399
  updateModelDateTimeStatuses(
@@ -3409,6 +3444,16 @@ function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
3409
3444
  )
3410
3445
  );
3411
3446
  }
3447
+ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
3448
+ if (!previousDateTime?.length) {
3449
+ return false;
3450
+ }
3451
+ return previousDateTime.some(
3452
+ (prev) => prev.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED && !nextDateTime?.some(
3453
+ (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED
3454
+ )
3455
+ );
3456
+ }
3412
3457
  function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3413
3458
  return relationDates.map((relationDate) => {
3414
3459
  const existsInEvent = eventDateTime?.some(
@@ -3422,11 +3467,11 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3422
3467
  }
3423
3468
 
3424
3469
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
3425
- var import_dayjs6 = __toESM(require("dayjs"));
3470
+ var import_dayjs7 = __toESM(require("dayjs"));
3426
3471
 
3427
3472
  // src/service/license/compliance/utils.ts
3428
3473
  var import_cluemart_shared33 = require("@timardex/cluemart-shared");
3429
- var import_dayjs5 = __toESM(require("dayjs"));
3474
+ var import_dayjs6 = __toESM(require("dayjs"));
3430
3475
 
3431
3476
  // src/service/license/compliance/event.ts
3432
3477
  var import_cluemart_shared29 = require("@timardex/cluemart-shared");
@@ -3658,11 +3703,11 @@ async function handlePartnerLicenceCompliance(user, now) {
3658
3703
 
3659
3704
  // src/service/license/compliance/vendor.ts
3660
3705
  var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3661
- var import_dayjs4 = __toESM(require("dayjs"));
3706
+ var import_dayjs5 = __toESM(require("dayjs"));
3662
3707
 
3663
3708
  // src/service/license/models.ts
3664
3709
  var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3665
- var import_dayjs3 = __toESM(require("dayjs"));
3710
+ var import_dayjs4 = __toESM(require("dayjs"));
3666
3711
  var import_graphql = require("graphql");
3667
3712
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3668
3713
  LicenceCategory2["EVENT"] = "event";
@@ -3743,7 +3788,7 @@ function getHighestLicenceForCategory(licences, category) {
3743
3788
  return highestLicence;
3744
3789
  }
3745
3790
  function createLicenceObject(expiryDate, licenceType) {
3746
- const today = (0, import_dayjs3.default)();
3791
+ const today = (0, import_dayjs4.default)();
3747
3792
  const expiryDateMapping = {
3748
3793
  [import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3749
3794
  [import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
@@ -4006,7 +4051,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4006
4051
  if (!stripe || stripe.currentPlan !== licenceType) {
4007
4052
  return false;
4008
4053
  }
4009
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs4.default)(stripe.paymentGracePeriodEndsAt) : null;
4054
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4010
4055
  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
4056
  if (hasActivePaymentGracePeriod) {
4012
4057
  return true;
@@ -4020,7 +4065,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4020
4065
  if (!stripe.endDate) {
4021
4066
  return false;
4022
4067
  }
4023
- const paidThrough = (0, import_dayjs4.default)(stripe.endDate);
4068
+ const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
4024
4069
  return paidThrough.isValid() && paidThrough.isAfter(now);
4025
4070
  }
4026
4071
  async function handleVendorLicenceCompliance(user, now) {
@@ -4037,7 +4082,7 @@ async function handleVendorLicenceCompliance(user, now) {
4037
4082
  (licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4038
4083
  );
4039
4084
  const expiredProLicences = proLicences.filter(
4040
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now)
4085
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4041
4086
  );
4042
4087
  const stripeProtectedLicenceTypes = new Set(
4043
4088
  expiredProLicences.filter(
@@ -4049,7 +4094,7 @@ async function handleVendorLicenceCompliance(user, now) {
4049
4094
  );
4050
4095
  const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
4051
4096
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4052
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4097
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4053
4098
  );
4054
4099
  if (!hasExpiredVendorLicence) {
4055
4100
  return;
@@ -4103,9 +4148,9 @@ async function vendorOwnerHasProLicence(vendorId) {
4103
4148
  if (!owner) {
4104
4149
  return false;
4105
4150
  }
4106
- const now = (0, import_dayjs4.default)();
4151
+ const now = (0, import_dayjs5.default)();
4107
4152
  const effectiveVendorLicences = owner.licences?.filter(
4108
- (licence) => licence?.licenceType && ((0, import_dayjs4.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4153
+ (licence) => licence?.licenceType && ((0, import_dayjs5.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4109
4154
  owner,
4110
4155
  licence.licenceType,
4111
4156
  now
@@ -4142,7 +4187,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4142
4187
  }
4143
4188
  function hasValidLicence(licences, licenceTypes, now) {
4144
4189
  return licences.some(
4145
- (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4190
+ (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
4146
4191
  );
4147
4192
  }
4148
4193
  async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
@@ -4169,7 +4214,7 @@ async function processUserCompliance(user, now) {
4169
4214
  }
4170
4215
 
4171
4216
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
4172
- async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs6.default)()) {
4217
+ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs7.default)()) {
4173
4218
  const user = await UserModel.findById(userId);
4174
4219
  if (!user) {
4175
4220
  return;
@@ -4177,7 +4222,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
4177
4222
  await processUserCompliance(user, now);
4178
4223
  }
4179
4224
  async function ensureUserLicenseCompliance() {
4180
- const now = (0, import_dayjs6.default)();
4225
+ const now = (0, import_dayjs7.default)();
4181
4226
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
4182
4227
  const nowDate = now.toDate();
4183
4228
  const users = await UserModel.find({
@@ -4252,7 +4297,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
4252
4297
  }
4253
4298
 
4254
4299
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4255
- var import_dayjs8 = __toESM(require("dayjs"));
4300
+ var import_dayjs9 = __toESM(require("dayjs"));
4256
4301
 
4257
4302
  // src/service/license/reminder/reminderWindow.ts
4258
4303
  var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
@@ -4261,7 +4306,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4261
4306
  // src/service/license/reminder/utils.ts
4262
4307
  var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4263
4308
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4264
- var import_dayjs7 = __toESM(require("dayjs"));
4309
+ var import_dayjs8 = __toESM(require("dayjs"));
4265
4310
 
4266
4311
  // src/service/license/reminder/vendor.ts
4267
4312
  async function getVendorResourceInfo(userId, vendorId) {
@@ -4320,7 +4365,7 @@ async function checkAndCreateNotification(payload) {
4320
4365
  }
4321
4366
  }
4322
4367
  function isLicenseExpiringIn7Days(expiryDate, now) {
4323
- const expiry = (0, import_dayjs7.default)(expiryDate);
4368
+ const expiry = (0, import_dayjs8.default)(expiryDate);
4324
4369
  const hoursUntilExpiry = expiry.diff(now, "hour", true);
4325
4370
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
4326
4371
  }
@@ -4398,7 +4443,7 @@ function getLicenceExpiryMode(licenceType) {
4398
4443
  }
4399
4444
  async function sendLicenseReminder(user, licence) {
4400
4445
  const licenceName = getLicenseName(licence.licenceType);
4401
- const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4446
+ const expiryDate = (0, import_dayjs8.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4402
4447
  const userId = String(user._id);
4403
4448
  const resourceInfo = await getLicenseResourceInfo(user, licence);
4404
4449
  if (!resourceInfo) {
@@ -4430,7 +4475,7 @@ async function sendLicenseReminder(user, licence) {
4430
4475
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
4431
4476
  }
4432
4477
  async function processLicenseReminder(licence, now) {
4433
- if ((0, import_dayjs7.default)(licence.expiryDate).isBefore(now)) {
4478
+ if ((0, import_dayjs8.default)(licence.expiryDate).isBefore(now)) {
4434
4479
  return false;
4435
4480
  }
4436
4481
  if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
@@ -4484,7 +4529,7 @@ async function processUserLicenseReminders(user, now) {
4484
4529
 
4485
4530
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4486
4531
  async function remindUsersAboutLicenseExpiration() {
4487
- const now = (0, import_dayjs8.default)();
4532
+ const now = (0, import_dayjs9.default)();
4488
4533
  console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
4489
4534
  const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
4490
4535
  const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
@@ -4537,6 +4582,7 @@ async function remindUsersAboutLicenseExpiration() {
4537
4582
  createLicenceObject,
4538
4583
  dedupeArchivedSlotsByStartDateTime,
4539
4584
  didRemoveAnyEventDates,
4585
+ didRemoveAnyStartedDates,
4540
4586
  downgradeVendorProFeatures,
4541
4587
  ensureUserLicenseCompliance,
4542
4588
  ensureUserLicenseComplianceForUser,