@timardex/cluemart-server-shared 1.0.207 → 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,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
  updateVendorBasedOnUserLicense: () => updateVendorBasedOnUserLicense,
82
83
  userLicenseSchema: () => userLicenseSchema
@@ -3446,6 +3447,7 @@ var EnumEventDateStatus = /* @__PURE__ */ ((EnumEventDateStatus22) => {
3446
3447
  EnumEventDateStatus22["ENDED"] = "Ended";
3447
3448
  EnumEventDateStatus22["RE_SCHEDULED"] = "Rescheduled";
3448
3449
  EnumEventDateStatus22["CANCELED"] = "Canceled";
3450
+ EnumEventDateStatus22["INVALID"] = "Invalid";
3449
3451
  return EnumEventDateStatus22;
3450
3452
  })(EnumEventDateStatus || {});
3451
3453
  var EnumSubscriptionStatus = /* @__PURE__ */ ((EnumSubscriptionStatus22) => {
@@ -3562,6 +3564,8 @@ var gameScreenIdentifierList = [
3562
3564
  match: "/visitors"
3563
3565
  }
3564
3566
  ];
3567
+ var dateFormat = "DD-MM-YYYY";
3568
+ var timeFormat = "HH:mm";
3565
3569
  import_dayjs.default.extend(import_customParseFormat.default);
3566
3570
  import_dayjs.default.extend(import_utc.default);
3567
3571
  import_dayjs.default.extend(import_timezone.default);
@@ -5227,8 +5231,8 @@ var EVENT = gql`
5227
5231
  ${RELATION_DATES_FRAGMENT}
5228
5232
  `;
5229
5233
  var GET_EVENTS = gql`
5230
- query getEvents {
5231
- events {
5234
+ query getEvents($dateStatus: EnumEventDateStatus) {
5235
+ events(dateStatus: $dateStatus) {
5232
5236
  ...EventListItemFields
5233
5237
  }
5234
5238
  }
@@ -5254,24 +5258,49 @@ var GET_EVENTS_BY_REGION = gql`
5254
5258
  query getEventsByRegion(
5255
5259
  $region: String!
5256
5260
  $options: ResourcesByRegionOptions
5261
+ $dateStatus: EnumEventDateStatus
5257
5262
  ) {
5258
- eventsByRegion(region: $region, options: $options) {
5263
+ eventsByRegion(
5264
+ region: $region
5265
+ options: $options
5266
+ dateStatus: $dateStatus
5267
+ ) {
5259
5268
  ...EventListItemFields
5260
5269
  }
5261
5270
  }
5262
5271
  ${EVENT_LIST_ITEM}
5263
5272
  `;
5264
5273
  var SEARCH_EVENTS = gql`
5265
- query searchEvents($region: String, $search: String, $tags: [String]) {
5266
- 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
+ ) {
5267
5286
  ...EventListItemFields
5268
5287
  }
5269
5288
  }
5270
5289
  ${EVENT_LIST_ITEM}
5271
5290
  `;
5272
5291
  var GET_EVENTS_NEAR_ME = gql`
5273
- query getEventsNearMe($latitude: Float!, $longitude: Float!, $radius: Int) {
5274
- 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
+ ) {
5275
5304
  ...EventListItemFields
5276
5305
  }
5277
5306
  }
@@ -7944,6 +7973,8 @@ var schema3 = new MongooseSchema7(
7944
7973
  schema3.index({ "location.geo": "2dsphere" });
7945
7974
  schema3.index({ name: 1 });
7946
7975
  schema3.index({ region: 1 });
7976
+ schema3.index({ deletedAt: 1 });
7977
+ schema3.index({ "dateTime.dateStatus": 1 });
7947
7978
  var GoogleImportedMarketModel = import_mongoose7.default.models.GoogleImportedMarket || import_mongoose7.default.model("GoogleImportedMarket", schema3);
7948
7979
 
7949
7980
  // src/mongoose/Notification.ts
@@ -7981,7 +8012,7 @@ schema4.index({ isRead: 1, userId: 1 });
7981
8012
  schema4.index({ createdAt: -1, userId: 1 });
7982
8013
  var NotificationModel = import_mongoose8.default.models.Notification || import_mongoose8.default.model("Notification", schema4);
7983
8014
 
7984
- // node_modules/@timardex/cluemart-shared/dist/chunk-6B75Q67V.mjs
8015
+ // node_modules/@timardex/cluemart-shared/dist/chunk-4SNW63TJ.mjs
7985
8016
  var EnumOSPlatform2 = /* @__PURE__ */ ((EnumOSPlatform22) => {
7986
8017
  EnumOSPlatform22["ANDROID"] = "android";
7987
8018
  EnumOSPlatform22["IOS"] = "ios";
@@ -8490,6 +8521,8 @@ schema12.index({ region: 1 });
8490
8521
  schema12.index({ "location.geo": "2dsphere" });
8491
8522
  schema12.index({ tags: 1 });
8492
8523
  schema12.index({ "associates.email": 1 });
8524
+ schema12.index({ deletedAt: 1 });
8525
+ schema12.index({ "dateTime.dateStatus": 1 });
8493
8526
  var EventModel = import_mongoose16.default.models.Event || import_mongoose16.default.model("Event", schema12);
8494
8527
 
8495
8528
  // src/mongoose/Partner.ts
@@ -9170,7 +9203,134 @@ function convertObjectIdsToStrings(obj) {
9170
9203
  return obj;
9171
9204
  }
9172
9205
 
9173
- // src/service/event.ts
9206
+ // src/service/event/updateAllEventDateTimeStatuses.ts
9207
+ var import_dayjs2 = __toESM(require("dayjs"));
9208
+ var import_customParseFormat2 = __toESM(require("dayjs/plugin/customParseFormat"));
9209
+ var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
9210
+ import_dayjs2.default.extend(import_customParseFormat2.default);
9211
+ import_dayjs2.default.extend(import_isoWeek.default);
9212
+ function getFutureEventStatus(startDateTime, now) {
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")) {
9218
+ return EnumEventDateStatus.TODAY;
9219
+ }
9220
+ if (startDateTime.isSame(now.add(1, "day"), "day")) {
9221
+ return EnumEventDateStatus.TOMORROW;
9222
+ }
9223
+ if (startDateTime.isSame(now, "isoWeek")) {
9224
+ return EnumEventDateStatus.THIS_WEEK;
9225
+ }
9226
+ if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
9227
+ return EnumEventDateStatus.NEXT_WEEK;
9228
+ }
9229
+ return EnumEventDateStatus.UPCOMING;
9230
+ }
9231
+ function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
9232
+ const dateTimeFormat = `${dateFormat} ${timeFormat}`;
9233
+ const startDateTime = (0, import_dayjs2.default)(
9234
+ `${dateTime.startDate} ${dateTime.startTime}`,
9235
+ dateTimeFormat,
9236
+ true
9237
+ );
9238
+ const endDateTime = (0, import_dayjs2.default)(
9239
+ `${dateTime.endDate} ${dateTime.endTime}`,
9240
+ dateTimeFormat,
9241
+ true
9242
+ );
9243
+ if (!startDateTime.isValid() || !endDateTime.isValid()) {
9244
+ return {
9245
+ ...dateTime,
9246
+ dateStatus: EnumEventDateStatus.INVALID
9247
+ };
9248
+ }
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
+ }
9262
+ } else {
9263
+ dateStatus = EnumEventDateStatus.ENDED;
9264
+ }
9265
+ return {
9266
+ ...dateTime,
9267
+ dateStatus
9268
+ };
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
9174
9334
  async function findEventOrImportedMarketById(resourceId) {
9175
9335
  if (!resourceId) {
9176
9336
  return null;
@@ -9208,7 +9368,7 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
9208
9368
 
9209
9369
  // src/types/index.ts
9210
9370
  var import_express = __toESM(require("express"));
9211
- var import_mongoose32 = __toESM(require("mongoose"));
9371
+ var import_mongoose33 = __toESM(require("mongoose"));
9212
9372
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
9213
9373
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
9214
9374
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -9265,6 +9425,7 @@ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
9265
9425
  sendPushNotifications,
9266
9426
  termsAgreementSchema,
9267
9427
  updateAdStatuses,
9428
+ updateAllEventDateTimeStatuses,
9268
9429
  updateRelationDatesToUnavailable,
9269
9430
  updateVendorBasedOnUserLicense,
9270
9431
  userLicenseSchema