@timardex/cluemart-server-shared 1.0.208 → 1.0.210

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
@@ -69,7 +69,7 @@ __export(index_exports, {
69
69
  findEventOrImportedMarketById: () => findEventOrImportedMarketById,
70
70
  locationGeoSchema: () => locationGeoSchema,
71
71
  locationsSchema: () => locationsSchema,
72
- mongoose: () => import_mongoose32.default,
72
+ mongoose: () => import_mongoose33.default,
73
73
  refundPolicySchema: () => refundPolicySchema,
74
74
  relationDatesSchema: () => relationDatesSchema,
75
75
  resourceRelationsSchema: () => resourceRelationsSchema,
@@ -77,8 +77,8 @@ __export(index_exports, {
77
77
  sendPushNotifications: () => sendPushNotifications,
78
78
  termsAgreementSchema: () => termsAgreementSchema,
79
79
  updateAdStatuses: () => updateAdStatuses,
80
+ updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
80
81
  updateRelationDatesToUnavailable: () => updateRelationDatesToUnavailable,
81
- updateSingleDateTimeStatus: () => updateSingleDateTimeStatus,
82
82
  updateVendorBasedOnUserLicense: () => updateVendorBasedOnUserLicense,
83
83
  userLicenseSchema: () => userLicenseSchema
84
84
  });
@@ -3447,6 +3447,7 @@ var EnumEventDateStatus = /* @__PURE__ */ ((EnumEventDateStatus22) => {
3447
3447
  EnumEventDateStatus22["ENDED"] = "Ended";
3448
3448
  EnumEventDateStatus22["RE_SCHEDULED"] = "Rescheduled";
3449
3449
  EnumEventDateStatus22["CANCELED"] = "Canceled";
3450
+ EnumEventDateStatus22["INVALID"] = "Invalid";
3450
3451
  return EnumEventDateStatus22;
3451
3452
  })(EnumEventDateStatus || {});
3452
3453
  var EnumSubscriptionStatus = /* @__PURE__ */ ((EnumSubscriptionStatus22) => {
@@ -5230,8 +5231,8 @@ var EVENT = gql`
5230
5231
  ${RELATION_DATES_FRAGMENT}
5231
5232
  `;
5232
5233
  var GET_EVENTS = gql`
5233
- query getEvents {
5234
- events {
5234
+ query getEvents($dateStatus: EnumEventDateStatus) {
5235
+ events(dateStatus: $dateStatus) {
5235
5236
  ...EventListItemFields
5236
5237
  }
5237
5238
  }
@@ -5257,24 +5258,49 @@ var GET_EVENTS_BY_REGION = gql`
5257
5258
  query getEventsByRegion(
5258
5259
  $region: String!
5259
5260
  $options: ResourcesByRegionOptions
5261
+ $dateStatus: EnumEventDateStatus
5260
5262
  ) {
5261
- eventsByRegion(region: $region, options: $options) {
5263
+ eventsByRegion(
5264
+ region: $region
5265
+ options: $options
5266
+ dateStatus: $dateStatus
5267
+ ) {
5262
5268
  ...EventListItemFields
5263
5269
  }
5264
5270
  }
5265
5271
  ${EVENT_LIST_ITEM}
5266
5272
  `;
5267
5273
  var SEARCH_EVENTS = gql`
5268
- query searchEvents($region: String, $search: String, $tags: [String]) {
5269
- eventsSearch(region: $region, search: $search, tags: $tags) {
5274
+ query searchEvents(
5275
+ $region: String
5276
+ $search: String
5277
+ $tags: [String]
5278
+ $dateStatus: EnumEventDateStatus
5279
+ ) {
5280
+ eventsSearch(
5281
+ region: $region
5282
+ search: $search
5283
+ tags: $tags
5284
+ dateStatus: $dateStatus
5285
+ ) {
5270
5286
  ...EventListItemFields
5271
5287
  }
5272
5288
  }
5273
5289
  ${EVENT_LIST_ITEM}
5274
5290
  `;
5275
5291
  var GET_EVENTS_NEAR_ME = gql`
5276
- query getEventsNearMe($latitude: Float!, $longitude: Float!, $radius: Int) {
5277
- eventsNearMe(latitude: $latitude, longitude: $longitude, radius: $radius) {
5292
+ query getEventsNearMe(
5293
+ $latitude: Float!
5294
+ $longitude: Float!
5295
+ $radius: Int
5296
+ $dateStatus: EnumEventDateStatus
5297
+ ) {
5298
+ eventsNearMe(
5299
+ latitude: $latitude
5300
+ longitude: $longitude
5301
+ radius: $radius
5302
+ dateStatus: $dateStatus
5303
+ ) {
5278
5304
  ...EventListItemFields
5279
5305
  }
5280
5306
  }
@@ -7947,6 +7973,8 @@ var schema3 = new MongooseSchema7(
7947
7973
  schema3.index({ "location.geo": "2dsphere" });
7948
7974
  schema3.index({ name: 1 });
7949
7975
  schema3.index({ region: 1 });
7976
+ schema3.index({ deletedAt: 1 });
7977
+ schema3.index({ "dateTime.dateStatus": 1 });
7950
7978
  var GoogleImportedMarketModel = import_mongoose7.default.models.GoogleImportedMarket || import_mongoose7.default.model("GoogleImportedMarket", schema3);
7951
7979
 
7952
7980
  // src/mongoose/Notification.ts
@@ -7984,7 +8012,7 @@ schema4.index({ isRead: 1, userId: 1 });
7984
8012
  schema4.index({ createdAt: -1, userId: 1 });
7985
8013
  var NotificationModel = import_mongoose8.default.models.Notification || import_mongoose8.default.model("Notification", schema4);
7986
8014
 
7987
- // node_modules/@timardex/cluemart-shared/dist/chunk-6B75Q67V.mjs
8015
+ // node_modules/@timardex/cluemart-shared/dist/chunk-4SNW63TJ.mjs
7988
8016
  var EnumOSPlatform2 = /* @__PURE__ */ ((EnumOSPlatform22) => {
7989
8017
  EnumOSPlatform22["ANDROID"] = "android";
7990
8018
  EnumOSPlatform22["IOS"] = "ios";
@@ -8493,6 +8521,8 @@ schema12.index({ region: 1 });
8493
8521
  schema12.index({ "location.geo": "2dsphere" });
8494
8522
  schema12.index({ tags: 1 });
8495
8523
  schema12.index({ "associates.email": 1 });
8524
+ schema12.index({ deletedAt: 1 });
8525
+ schema12.index({ "dateTime.dateStatus": 1 });
8496
8526
  var EventModel = import_mongoose16.default.models.Event || import_mongoose16.default.model("Event", schema12);
8497
8527
 
8498
8528
  // src/mongoose/Partner.ts
@@ -9173,32 +9203,21 @@ function convertObjectIdsToStrings(obj) {
9173
9203
  return obj;
9174
9204
  }
9175
9205
 
9176
- // src/service/event.ts
9206
+ // src/service/event/updateAllEventDateTimeStatuses.ts
9177
9207
  var import_dayjs2 = __toESM(require("dayjs"));
9178
9208
  var import_customParseFormat2 = __toESM(require("dayjs/plugin/customParseFormat"));
9179
9209
  var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
9180
- var import_isToday = __toESM(require("dayjs/plugin/isToday"));
9181
- var import_isTomorrow = __toESM(require("dayjs/plugin/isTomorrow"));
9182
9210
  import_dayjs2.default.extend(import_customParseFormat2.default);
9183
- import_dayjs2.default.extend(import_isToday.default);
9184
- import_dayjs2.default.extend(import_isTomorrow.default);
9185
9211
  import_dayjs2.default.extend(import_isoWeek.default);
9186
- async function findEventOrImportedMarketById(resourceId) {
9187
- if (!resourceId) {
9188
- return null;
9189
- }
9190
- const normalizedId = convertObjectIdsToStrings(resourceId);
9191
- const [eventDoc, googleImportedDoc] = await Promise.all([
9192
- EventModel.findById(normalizedId).select("_id name").lean().exec(),
9193
- GoogleImportedMarketModel.findById(normalizedId).select("_id name").lean().exec()
9194
- ]);
9195
- return eventDoc ?? googleImportedDoc;
9196
- }
9197
9212
  function getFutureEventStatus(startDateTime, now) {
9198
- if (startDateTime.isToday()) {
9213
+ const hoursUntilStart = startDateTime.diff(now, "hour", true);
9214
+ if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
9215
+ return EnumEventDateStatus.STARTING_SOON;
9216
+ }
9217
+ if (startDateTime.isSame(now, "day")) {
9199
9218
  return EnumEventDateStatus.TODAY;
9200
9219
  }
9201
- if (startDateTime.isTomorrow()) {
9220
+ if (startDateTime.isSame(now.add(1, "day"), "day")) {
9202
9221
  return EnumEventDateStatus.TOMORROW;
9203
9222
  }
9204
9223
  if (startDateTime.isSame(now, "isoWeek")) {
@@ -9207,41 +9226,122 @@ function getFutureEventStatus(startDateTime, now) {
9207
9226
  if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
9208
9227
  return EnumEventDateStatus.NEXT_WEEK;
9209
9228
  }
9210
- const hoursUntilStart = startDateTime.diff(now, "hour", true);
9211
- if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
9212
- return EnumEventDateStatus.STARTING_SOON;
9213
- }
9214
9229
  return EnumEventDateStatus.UPCOMING;
9215
9230
  }
9216
- function updateSingleDateTimeStatus(dateTime) {
9217
- const now = (0, import_dayjs2.default)();
9231
+ function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
9232
+ const dateTimeFormat = `${dateFormat} ${timeFormat}`;
9218
9233
  const startDateTime = (0, import_dayjs2.default)(
9219
9234
  `${dateTime.startDate} ${dateTime.startTime}`,
9220
- `${dateFormat} ${timeFormat}`
9235
+ dateTimeFormat,
9236
+ true
9221
9237
  );
9222
9238
  const endDateTime = (0, import_dayjs2.default)(
9223
9239
  `${dateTime.endDate} ${dateTime.endTime}`,
9224
- `${dateFormat} ${timeFormat}`
9240
+ dateTimeFormat,
9241
+ true
9225
9242
  );
9226
9243
  if (!startDateTime.isValid() || !endDateTime.isValid()) {
9227
9244
  return {
9228
9245
  ...dateTime,
9229
- dateStatus: null
9246
+ dateStatus: EnumEventDateStatus.INVALID
9230
9247
  };
9231
9248
  }
9232
- let dateStatus = null;
9233
- if (endDateTime.isBefore(now)) {
9234
- dateStatus = EnumEventDateStatus.ENDED;
9235
- } else if (startDateTime.isBefore(now) && endDateTime.isAfter(now)) {
9236
- dateStatus = EnumEventDateStatus.STARTED;
9249
+ if (endDateTime.isBefore(startDateTime)) {
9250
+ return {
9251
+ ...dateTime,
9252
+ dateStatus: EnumEventDateStatus.INVALID
9253
+ };
9254
+ }
9255
+ let dateStatus;
9256
+ if (endDateTime.isAfter(now)) {
9257
+ if (startDateTime.isAfter(now)) {
9258
+ dateStatus = getFutureEventStatus(startDateTime, now);
9259
+ } else {
9260
+ dateStatus = EnumEventDateStatus.STARTED;
9261
+ }
9237
9262
  } else {
9238
- dateStatus = getFutureEventStatus(startDateTime, now);
9263
+ dateStatus = EnumEventDateStatus.ENDED;
9239
9264
  }
9240
9265
  return {
9241
9266
  ...dateTime,
9242
9267
  dateStatus
9243
9268
  };
9244
9269
  }
9270
+ var dateTimeStatusFilter = {
9271
+ dateTime: { $ne: [], $type: "array" },
9272
+ deletedAt: null
9273
+ };
9274
+ var CURSOR_BATCH_SIZE = 50;
9275
+ function hasDateTimeStatusChanges(stored, updated) {
9276
+ if (stored.length !== updated.length) {
9277
+ return true;
9278
+ }
9279
+ return stored.some(
9280
+ (slot, index) => slot.dateStatus !== updated[index].dateStatus
9281
+ );
9282
+ }
9283
+ async function updateModelDateTimeStatuses(model, now) {
9284
+ let updated = 0;
9285
+ const cursor = model.find(dateTimeStatusFilter).select({ _id: 1, dateTime: 1 }).lean().cursor({ batchSize: CURSOR_BATCH_SIZE });
9286
+ let bulkOps = [];
9287
+ const flushBulkWrites = async () => {
9288
+ if (!bulkOps.length) {
9289
+ return;
9290
+ }
9291
+ await model.bulkWrite(bulkOps);
9292
+ updated += bulkOps.length;
9293
+ bulkOps = [];
9294
+ };
9295
+ try {
9296
+ for await (const doc of cursor) {
9297
+ const dateTime = doc.dateTime.map(
9298
+ (slot) => updateSingleDateTimeStatus(slot, now)
9299
+ );
9300
+ if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
9301
+ continue;
9302
+ }
9303
+ bulkOps.push({
9304
+ updateOne: {
9305
+ filter: { _id: doc._id },
9306
+ update: { $set: { dateTime } }
9307
+ }
9308
+ });
9309
+ if (bulkOps.length >= CURSOR_BATCH_SIZE) {
9310
+ await flushBulkWrites();
9311
+ }
9312
+ }
9313
+ await flushBulkWrites();
9314
+ } finally {
9315
+ await cursor.close().catch(() => void 0);
9316
+ }
9317
+ return updated;
9318
+ }
9319
+ async function updateAllEventDateTimeStatuses() {
9320
+ const now = (0, import_dayjs2.default)();
9321
+ const [eventCount, marketCount] = await Promise.all([
9322
+ updateModelDateTimeStatuses(EventModel, now),
9323
+ updateModelDateTimeStatuses(
9324
+ GoogleImportedMarketModel,
9325
+ now
9326
+ )
9327
+ ]);
9328
+ console.log(
9329
+ `\u2705 Event dateTime statuses updated: events=${eventCount} changed, google imported markets=${marketCount} changed`
9330
+ );
9331
+ }
9332
+
9333
+ // src/service/event/findEventOrImportedMarketById.ts
9334
+ async function findEventOrImportedMarketById(resourceId) {
9335
+ if (!resourceId) {
9336
+ return null;
9337
+ }
9338
+ const normalizedId = convertObjectIdsToStrings(resourceId);
9339
+ const [eventDoc, googleImportedDoc] = await Promise.all([
9340
+ EventModel.findById(normalizedId).select("_id name").lean().exec(),
9341
+ GoogleImportedMarketModel.findById(normalizedId).select("_id name").lean().exec()
9342
+ ]);
9343
+ return eventDoc ?? googleImportedDoc;
9344
+ }
9245
9345
 
9246
9346
  // src/service/relations.ts
9247
9347
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
@@ -9268,7 +9368,7 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
9268
9368
 
9269
9369
  // src/types/index.ts
9270
9370
  var import_express = __toESM(require("express"));
9271
- var import_mongoose32 = __toESM(require("mongoose"));
9371
+ var import_mongoose33 = __toESM(require("mongoose"));
9272
9372
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
9273
9373
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
9274
9374
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -9325,8 +9425,8 @@ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
9325
9425
  sendPushNotifications,
9326
9426
  termsAgreementSchema,
9327
9427
  updateAdStatuses,
9428
+ updateAllEventDateTimeStatuses,
9328
9429
  updateRelationDatesToUnavailable,
9329
- updateSingleDateTimeStatus,
9330
9430
  updateVendorBasedOnUserLicense,
9331
9431
  userLicenseSchema
9332
9432
  });