@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.
package/dist/index.d.mts CHANGED
@@ -1126,11 +1126,24 @@ type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
1126
1126
  declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
1127
1127
 
1128
1128
  type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
1129
+ type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
1129
1130
  /**
1130
1131
  * Returns true when at least one startDate/startTime slot from the previous
1131
1132
  * schedule is absent from the next schedule (i.e. a date was removed).
1132
1133
  */
1133
1134
  declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | undefined, nextDateTime: EventDateSlot[] | undefined): boolean;
1135
+ /**
1136
+ * Returns true when a slot that was `STARTED` in the previous schedule is no
1137
+ * longer `STARTED` in the next schedule (e.g. canceled or rescheduled).
1138
+ *
1139
+ * This catches the `STARTED → CANCELED` transition that
1140
+ * {@link didRemoveAnyEventDates} misses: that function only compares
1141
+ * `startDate`/`startTime` presence, so a slot that still exists but whose
1142
+ * `dateStatus` changed is not flagged. (Its callers filter to future-only
1143
+ * schedules, which also drop `STARTED`.) Without this extra status check, a
1144
+ * started slot that gets canceled would leave its relation dates untouched.
1145
+ */
1146
+ declare function didRemoveAnyStartedDates(previousDateTime: StartedDateSlot[] | undefined, nextDateTime: StartedDateSlot[] | undefined): boolean;
1134
1147
  /**
1135
1148
  * Helper: Update relationDates based on event's dateTime
1136
1149
  * Marks dates as UNAVAILABLE if they no longer exist in the event's dateTime.
@@ -1412,4 +1425,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
1412
1425
  resourceType: EnumResourceType;
1413
1426
  }): Promise<void>;
1414
1427
 
1415
- export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, type AdImpressionEntry, AdImpressionModel, AdModel, AdSettingsModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, DEFAULT_AD_SETTINGS, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAppSettingsType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
1428
+ export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, type AdImpressionEntry, AdImpressionModel, AdModel, AdSettingsModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, DEFAULT_AD_SETTINGS, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAppSettingsType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
package/dist/index.d.ts CHANGED
@@ -1126,11 +1126,24 @@ type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
1126
1126
  declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
1127
1127
 
1128
1128
  type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
1129
+ type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
1129
1130
  /**
1130
1131
  * Returns true when at least one startDate/startTime slot from the previous
1131
1132
  * schedule is absent from the next schedule (i.e. a date was removed).
1132
1133
  */
1133
1134
  declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | undefined, nextDateTime: EventDateSlot[] | undefined): boolean;
1135
+ /**
1136
+ * Returns true when a slot that was `STARTED` in the previous schedule is no
1137
+ * longer `STARTED` in the next schedule (e.g. canceled or rescheduled).
1138
+ *
1139
+ * This catches the `STARTED → CANCELED` transition that
1140
+ * {@link didRemoveAnyEventDates} misses: that function only compares
1141
+ * `startDate`/`startTime` presence, so a slot that still exists but whose
1142
+ * `dateStatus` changed is not flagged. (Its callers filter to future-only
1143
+ * schedules, which also drop `STARTED`.) Without this extra status check, a
1144
+ * started slot that gets canceled would leave its relation dates untouched.
1145
+ */
1146
+ declare function didRemoveAnyStartedDates(previousDateTime: StartedDateSlot[] | undefined, nextDateTime: StartedDateSlot[] | undefined): boolean;
1134
1147
  /**
1135
1148
  * Helper: Update relationDates based on event's dateTime
1136
1149
  * Marks dates as UNAVAILABLE if they no longer exist in the event's dateTime.
@@ -1412,4 +1425,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
1412
1425
  resourceType: EnumResourceType;
1413
1426
  }): Promise<void>;
1414
1427
 
1415
- export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, type AdImpressionEntry, AdImpressionModel, AdModel, AdSettingsModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, DEFAULT_AD_SETTINGS, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAppSettingsType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
1428
+ export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, type AdImpressionEntry, AdImpressionModel, AdModel, AdSettingsModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, DEFAULT_AD_SETTINGS, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAppSettingsType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
package/dist/index.mjs CHANGED
@@ -3192,10 +3192,17 @@ import {
3192
3192
  filterDatesByFutureStatus,
3193
3193
  updateSingleDateTimeStatus
3194
3194
  } from "@timardex/cluemart-shared";
3195
- import dayjs2 from "dayjs";
3195
+ import dayjs3 from "dayjs";
3196
3196
 
3197
3197
  // src/service/event/archiveEndedEventDates.ts
3198
- import { EnumEventDateStatus as EnumEventDateStatus6 } from "@timardex/cluemart-shared";
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: [EnumEventDateStatus7.ENDED, EnumEventDateStatus7.INVALID]
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(eventOps);
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
- if (archive.length === 0 && discard.length === 0) {
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 = dayjs2();
3431
+ const now = dayjs3();
3394
3432
  const [eventCount, marketCount] = await Promise.all([
3395
3433
  updateModelDateTimeStatuses(EventModel, now),
3396
3434
  updateModelDateTimeStatuses(
@@ -3431,6 +3469,7 @@ async function findEventOrImportedMarketById(resourceId) {
3431
3469
 
3432
3470
  // src/service/relations.ts
3433
3471
  import {
3472
+ EnumEventDateStatus as EnumEventDateStatus8,
3434
3473
  EnumInviteStatus as EnumInviteStatus2
3435
3474
  } from "@timardex/cluemart-shared";
3436
3475
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
@@ -3443,6 +3482,16 @@ function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
3443
3482
  )
3444
3483
  );
3445
3484
  }
3485
+ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
3486
+ if (!previousDateTime?.length) {
3487
+ return false;
3488
+ }
3489
+ return previousDateTime.some(
3490
+ (prev) => prev.dateStatus === EnumEventDateStatus8.STARTED && !nextDateTime?.some(
3491
+ (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === EnumEventDateStatus8.STARTED
3492
+ )
3493
+ );
3494
+ }
3446
3495
  function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3447
3496
  return relationDates.map((relationDate) => {
3448
3497
  const existsInEvent = eventDateTime?.some(
@@ -3456,13 +3505,13 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3456
3505
  }
3457
3506
 
3458
3507
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
3459
- import dayjs6 from "dayjs";
3508
+ import dayjs7 from "dayjs";
3460
3509
 
3461
3510
  // src/service/license/compliance/utils.ts
3462
3511
  import {
3463
3512
  EnumUserLicence as EnumUserLicence10
3464
3513
  } from "@timardex/cluemart-shared";
3465
- import dayjs5 from "dayjs";
3514
+ import dayjs6 from "dayjs";
3466
3515
 
3467
3516
  // src/service/license/compliance/event.ts
3468
3517
  import { EnumUserLicence as EnumUserLicence6 } from "@timardex/cluemart-shared";
@@ -3700,7 +3749,7 @@ import {
3700
3749
  EnumUserLicence as EnumUserLicence9,
3701
3750
  vendorLicences
3702
3751
  } from "@timardex/cluemart-shared";
3703
- import dayjs4 from "dayjs";
3752
+ import dayjs5 from "dayjs";
3704
3753
 
3705
3754
  // src/service/license/models.ts
3706
3755
  import {
@@ -3709,7 +3758,7 @@ import {
3709
3758
  isNonVisitorResourceType,
3710
3759
  LicenceExpiryDate
3711
3760
  } from "@timardex/cluemart-shared";
3712
- import dayjs3 from "dayjs";
3761
+ import dayjs4 from "dayjs";
3713
3762
  import { GraphQLError } from "graphql";
3714
3763
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3715
3764
  LicenceCategory2["EVENT"] = "event";
@@ -3790,7 +3839,7 @@ function getHighestLicenceForCategory(licences, category) {
3790
3839
  return highestLicence;
3791
3840
  }
3792
3841
  function createLicenceObject(expiryDate, licenceType) {
3793
- const today = dayjs3();
3842
+ const today = dayjs4();
3794
3843
  const expiryDateMapping = {
3795
3844
  [LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3796
3845
  [LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
@@ -4053,7 +4102,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4053
4102
  if (!stripe || stripe.currentPlan !== licenceType) {
4054
4103
  return false;
4055
4104
  }
4056
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs4(stripe.paymentGracePeriodEndsAt) : null;
4105
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs5(stripe.paymentGracePeriodEndsAt) : null;
4057
4106
  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
4107
  if (hasActivePaymentGracePeriod) {
4059
4108
  return true;
@@ -4067,7 +4116,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4067
4116
  if (!stripe.endDate) {
4068
4117
  return false;
4069
4118
  }
4070
- const paidThrough = dayjs4(stripe.endDate);
4119
+ const paidThrough = dayjs5(stripe.endDate);
4071
4120
  return paidThrough.isValid() && paidThrough.isAfter(now);
4072
4121
  }
4073
4122
  async function handleVendorLicenceCompliance(user, now) {
@@ -4084,7 +4133,7 @@ async function handleVendorLicenceCompliance(user, now) {
4084
4133
  (licence) => licence.licenceType !== EnumUserLicence9.STANDARD_VENDOR
4085
4134
  );
4086
4135
  const expiredProLicences = proLicences.filter(
4087
- (licence) => !dayjs4(licence.expiryDate).isAfter(now)
4136
+ (licence) => !dayjs5(licence.expiryDate).isAfter(now)
4088
4137
  );
4089
4138
  const stripeProtectedLicenceTypes = new Set(
4090
4139
  expiredProLicences.filter(
@@ -4096,7 +4145,7 @@ async function handleVendorLicenceCompliance(user, now) {
4096
4145
  );
4097
4146
  const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, vendorLicences, now);
4098
4147
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4099
- (licence) => !dayjs4(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4148
+ (licence) => !dayjs5(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4100
4149
  );
4101
4150
  if (!hasExpiredVendorLicence) {
4102
4151
  return;
@@ -4150,9 +4199,9 @@ async function vendorOwnerHasProLicence(vendorId) {
4150
4199
  if (!owner) {
4151
4200
  return false;
4152
4201
  }
4153
- const now = dayjs4();
4202
+ const now = dayjs5();
4154
4203
  const effectiveVendorLicences = owner.licences?.filter(
4155
- (licence) => licence?.licenceType && (dayjs4(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4204
+ (licence) => licence?.licenceType && (dayjs5(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4156
4205
  owner,
4157
4206
  licence.licenceType,
4158
4207
  now
@@ -4189,7 +4238,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4189
4238
  }
4190
4239
  function hasValidLicence(licences, licenceTypes, now) {
4191
4240
  return licences.some(
4192
- (licence) => licenceTypes.includes(licence.licenceType) && dayjs5(licence.expiryDate).isAfter(now)
4241
+ (licence) => licenceTypes.includes(licence.licenceType) && dayjs6(licence.expiryDate).isAfter(now)
4193
4242
  );
4194
4243
  }
4195
4244
  async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
@@ -4216,7 +4265,7 @@ async function processUserCompliance(user, now) {
4216
4265
  }
4217
4266
 
4218
4267
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
4219
- async function ensureUserLicenseComplianceForUser(userId, now = dayjs6()) {
4268
+ async function ensureUserLicenseComplianceForUser(userId, now = dayjs7()) {
4220
4269
  const user = await UserModel.findById(userId);
4221
4270
  if (!user) {
4222
4271
  return;
@@ -4224,7 +4273,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = dayjs6()) {
4224
4273
  await processUserCompliance(user, now);
4225
4274
  }
4226
4275
  async function ensureUserLicenseCompliance() {
4227
- const now = dayjs6();
4276
+ const now = dayjs7();
4228
4277
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
4229
4278
  const nowDate = now.toDate();
4230
4279
  const users = await UserModel.find({
@@ -4299,7 +4348,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
4299
4348
  }
4300
4349
 
4301
4350
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4302
- import dayjs8 from "dayjs";
4351
+ import dayjs9 from "dayjs";
4303
4352
 
4304
4353
  // src/service/license/reminder/reminderWindow.ts
4305
4354
  var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
@@ -4307,7 +4356,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4307
4356
 
4308
4357
  // src/service/license/reminder/utils.ts
4309
4358
  import {
4310
- dateFormat,
4359
+ dateFormat as dateFormat2,
4311
4360
  EnumNotificationResourceType as EnumNotificationResourceType6,
4312
4361
  EnumNotificationType as EnumNotificationType5,
4313
4362
  EnumUserLicence as EnumUserLicence11,
@@ -4315,7 +4364,7 @@ import {
4315
4364
  vendorLicences as vendorLicences2
4316
4365
  } from "@timardex/cluemart-shared";
4317
4366
  import { formatDate } from "@timardex/cluemart-shared/utils";
4318
- import dayjs7 from "dayjs";
4367
+ import dayjs8 from "dayjs";
4319
4368
 
4320
4369
  // src/service/license/reminder/vendor.ts
4321
4370
  async function getVendorResourceInfo(userId, vendorId) {
@@ -4374,7 +4423,7 @@ async function checkAndCreateNotification(payload) {
4374
4423
  }
4375
4424
  }
4376
4425
  function isLicenseExpiringIn7Days(expiryDate, now) {
4377
- const expiry = dayjs7(expiryDate);
4426
+ const expiry = dayjs8(expiryDate);
4378
4427
  const hoursUntilExpiry = expiry.diff(now, "hour", true);
4379
4428
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
4380
4429
  }
@@ -4452,7 +4501,7 @@ function getLicenceExpiryMode(licenceType) {
4452
4501
  }
4453
4502
  async function sendLicenseReminder(user, licence) {
4454
4503
  const licenceName = getLicenseName(licence.licenceType);
4455
- const expiryDate = dayjs7(licence.expiryDate).format(dateFormat);
4504
+ const expiryDate = dayjs8(licence.expiryDate).format(dateFormat2);
4456
4505
  const userId = String(user._id);
4457
4506
  const resourceInfo = await getLicenseResourceInfo(user, licence);
4458
4507
  if (!resourceInfo) {
@@ -4484,7 +4533,7 @@ async function sendLicenseReminder(user, licence) {
4484
4533
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
4485
4534
  }
4486
4535
  async function processLicenseReminder(licence, now) {
4487
- if (dayjs7(licence.expiryDate).isBefore(now)) {
4536
+ if (dayjs8(licence.expiryDate).isBefore(now)) {
4488
4537
  return false;
4489
4538
  }
4490
4539
  if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
@@ -4538,7 +4587,7 @@ async function processUserLicenseReminders(user, now) {
4538
4587
 
4539
4588
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4540
4589
  async function remindUsersAboutLicenseExpiration() {
4541
- const now = dayjs8();
4590
+ const now = dayjs9();
4542
4591
  console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
4543
4592
  const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
4544
4593
  const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
@@ -4635,6 +4684,7 @@ export {
4635
4684
  dateTimeSchema,
4636
4685
  dedupeArchivedSlotsByStartDateTime,
4637
4686
  didRemoveAnyEventDates,
4687
+ didRemoveAnyStartedDates,
4638
4688
  downgradeVendorProFeatures,
4639
4689
  ensureUserLicenseCompliance,
4640
4690
  ensureUserLicenseComplianceForUser,