@timardex/cluemart-server-shared 1.0.208 → 1.0.211

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