@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.
@@ -37,7 +37,7 @@ import {
37
37
  resourceRelationsSchema,
38
38
  termsAgreementSchema,
39
39
  userLicenseSchema
40
- } from "../chunk-3BUXU7KR.mjs";
40
+ } from "../chunk-7C3KPJ33.mjs";
41
41
  export {
42
42
  APP_SETTINGS_ID,
43
43
  AdModel,
@@ -37,6 +37,7 @@ __export(service_exports, {
37
37
  saveNotificationsInDb: () => saveNotificationsInDb,
38
38
  sendPushNotifications: () => sendPushNotifications,
39
39
  updateAdStatuses: () => updateAdStatuses,
40
+ updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
40
41
  updateRelationDatesToUnavailable: () => updateRelationDatesToUnavailable,
41
42
  updateSingleDateTimeStatus: () => updateSingleDateTimeStatus,
42
43
  updateVendorBasedOnUserLicense: () => updateVendorBasedOnUserLicense
@@ -3431,6 +3432,7 @@ var EnumEventDateStatus = /* @__PURE__ */ ((EnumEventDateStatus22) => {
3431
3432
  EnumEventDateStatus22["ENDED"] = "Ended";
3432
3433
  EnumEventDateStatus22["RE_SCHEDULED"] = "Rescheduled";
3433
3434
  EnumEventDateStatus22["CANCELED"] = "Canceled";
3435
+ EnumEventDateStatus22["INVALID"] = "Invalid";
3434
3436
  return EnumEventDateStatus22;
3435
3437
  })(EnumEventDateStatus || {});
3436
3438
  var EnumSubscriptionStatus = /* @__PURE__ */ ((EnumSubscriptionStatus22) => {
@@ -5214,8 +5216,8 @@ var EVENT = gql`
5214
5216
  ${RELATION_DATES_FRAGMENT}
5215
5217
  `;
5216
5218
  var GET_EVENTS = gql`
5217
- query getEvents {
5218
- events {
5219
+ query getEvents($dateStatus: EnumEventDateStatus) {
5220
+ events(dateStatus: $dateStatus) {
5219
5221
  ...EventListItemFields
5220
5222
  }
5221
5223
  }
@@ -5241,24 +5243,49 @@ var GET_EVENTS_BY_REGION = gql`
5241
5243
  query getEventsByRegion(
5242
5244
  $region: String!
5243
5245
  $options: ResourcesByRegionOptions
5246
+ $dateStatus: EnumEventDateStatus
5244
5247
  ) {
5245
- eventsByRegion(region: $region, options: $options) {
5248
+ eventsByRegion(
5249
+ region: $region
5250
+ options: $options
5251
+ dateStatus: $dateStatus
5252
+ ) {
5246
5253
  ...EventListItemFields
5247
5254
  }
5248
5255
  }
5249
5256
  ${EVENT_LIST_ITEM}
5250
5257
  `;
5251
5258
  var SEARCH_EVENTS = gql`
5252
- query searchEvents($region: String, $search: String, $tags: [String]) {
5253
- eventsSearch(region: $region, search: $search, tags: $tags) {
5259
+ query searchEvents(
5260
+ $region: String
5261
+ $search: String
5262
+ $tags: [String]
5263
+ $dateStatus: EnumEventDateStatus
5264
+ ) {
5265
+ eventsSearch(
5266
+ region: $region
5267
+ search: $search
5268
+ tags: $tags
5269
+ dateStatus: $dateStatus
5270
+ ) {
5254
5271
  ...EventListItemFields
5255
5272
  }
5256
5273
  }
5257
5274
  ${EVENT_LIST_ITEM}
5258
5275
  `;
5259
5276
  var GET_EVENTS_NEAR_ME = gql`
5260
- query getEventsNearMe($latitude: Float!, $longitude: Float!, $radius: Int) {
5261
- eventsNearMe(latitude: $latitude, longitude: $longitude, radius: $radius) {
5277
+ query getEventsNearMe(
5278
+ $latitude: Float!
5279
+ $longitude: Float!
5280
+ $radius: Int
5281
+ $dateStatus: EnumEventDateStatus
5282
+ ) {
5283
+ eventsNearMe(
5284
+ latitude: $latitude
5285
+ longitude: $longitude
5286
+ radius: $radius
5287
+ dateStatus: $dateStatus
5288
+ ) {
5262
5289
  ...EventListItemFields
5263
5290
  }
5264
5291
  }
@@ -7334,7 +7361,7 @@ async function saveNotificationsInDb(payload) {
7334
7361
  // src/service/sendPushNotifications.ts
7335
7362
  var import_expo_server_sdk = require("expo-server-sdk");
7336
7363
 
7337
- // node_modules/@timardex/cluemart-shared/dist/chunk-6B75Q67V.mjs
7364
+ // node_modules/@timardex/cluemart-shared/dist/chunk-4SNW63TJ.mjs
7338
7365
  var EnumOSPlatform2 = /* @__PURE__ */ ((EnumOSPlatform22) => {
7339
7366
  EnumOSPlatform22["ANDROID"] = "android";
7340
7367
  EnumOSPlatform22["IOS"] = "ios";
@@ -8130,6 +8157,8 @@ var schema5 = new MongooseSchema9(
8130
8157
  schema5.index({ "location.geo": "2dsphere" });
8131
8158
  schema5.index({ name: 1 });
8132
8159
  schema5.index({ region: 1 });
8160
+ schema5.index({ deletedAt: 1 });
8161
+ schema5.index({ "dateTime.dateStatus": 1 });
8133
8162
  var GoogleImportedMarketModel = import_mongoose10.default.models.GoogleImportedMarket || import_mongoose10.default.model("GoogleImportedMarket", schema5);
8134
8163
 
8135
8164
  // src/mongoose/ResourceActivity.ts
@@ -8612,6 +8641,8 @@ schema12.index({ region: 1 });
8612
8641
  schema12.index({ "location.geo": "2dsphere" });
8613
8642
  schema12.index({ tags: 1 });
8614
8643
  schema12.index({ "associates.email": 1 });
8644
+ schema12.index({ deletedAt: 1 });
8645
+ schema12.index({ "dateTime.dateStatus": 1 });
8615
8646
  var EventModel = import_mongoose17.default.models.Event || import_mongoose17.default.model("Event", schema12);
8616
8647
 
8617
8648
  // src/mongoose/Partner.ts
@@ -9134,32 +9165,21 @@ function convertObjectIdsToStrings(obj) {
9134
9165
  return obj;
9135
9166
  }
9136
9167
 
9137
- // src/service/event.ts
9168
+ // src/service/event/updateAllEventDateTimeStatuses.ts
9138
9169
  var import_dayjs2 = __toESM(require("dayjs"));
9139
9170
  var import_customParseFormat2 = __toESM(require("dayjs/plugin/customParseFormat"));
9140
9171
  var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
9141
- var import_isToday = __toESM(require("dayjs/plugin/isToday"));
9142
- var import_isTomorrow = __toESM(require("dayjs/plugin/isTomorrow"));
9143
9172
  import_dayjs2.default.extend(import_customParseFormat2.default);
9144
- import_dayjs2.default.extend(import_isToday.default);
9145
- import_dayjs2.default.extend(import_isTomorrow.default);
9146
9173
  import_dayjs2.default.extend(import_isoWeek.default);
9147
- async function findEventOrImportedMarketById(resourceId) {
9148
- if (!resourceId) {
9149
- return null;
9150
- }
9151
- const normalizedId = convertObjectIdsToStrings(resourceId);
9152
- const [eventDoc, googleImportedDoc] = await Promise.all([
9153
- EventModel.findById(normalizedId).select("_id name").lean().exec(),
9154
- GoogleImportedMarketModel.findById(normalizedId).select("_id name").lean().exec()
9155
- ]);
9156
- return eventDoc ?? googleImportedDoc;
9157
- }
9158
9174
  function getFutureEventStatus(startDateTime, now) {
9159
- if (startDateTime.isToday()) {
9175
+ const hoursUntilStart = startDateTime.diff(now, "hour", true);
9176
+ if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
9177
+ return EnumEventDateStatus.STARTING_SOON;
9178
+ }
9179
+ if (startDateTime.isSame(now, "day")) {
9160
9180
  return EnumEventDateStatus.TODAY;
9161
9181
  }
9162
- if (startDateTime.isTomorrow()) {
9182
+ if (startDateTime.isSame(now.add(1, "day"), "day")) {
9163
9183
  return EnumEventDateStatus.TOMORROW;
9164
9184
  }
9165
9185
  if (startDateTime.isSame(now, "isoWeek")) {
@@ -9168,41 +9188,122 @@ function getFutureEventStatus(startDateTime, now) {
9168
9188
  if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
9169
9189
  return EnumEventDateStatus.NEXT_WEEK;
9170
9190
  }
9171
- const hoursUntilStart = startDateTime.diff(now, "hour", true);
9172
- if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
9173
- return EnumEventDateStatus.STARTING_SOON;
9174
- }
9175
9191
  return EnumEventDateStatus.UPCOMING;
9176
9192
  }
9177
- function updateSingleDateTimeStatus(dateTime) {
9178
- const now = (0, import_dayjs2.default)();
9193
+ function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
9194
+ const dateTimeFormat = `${dateFormat} ${timeFormat}`;
9179
9195
  const startDateTime = (0, import_dayjs2.default)(
9180
9196
  `${dateTime.startDate} ${dateTime.startTime}`,
9181
- `${dateFormat} ${timeFormat}`
9197
+ dateTimeFormat,
9198
+ true
9182
9199
  );
9183
9200
  const endDateTime = (0, import_dayjs2.default)(
9184
9201
  `${dateTime.endDate} ${dateTime.endTime}`,
9185
- `${dateFormat} ${timeFormat}`
9202
+ dateTimeFormat,
9203
+ true
9186
9204
  );
9187
9205
  if (!startDateTime.isValid() || !endDateTime.isValid()) {
9188
9206
  return {
9189
9207
  ...dateTime,
9190
- dateStatus: null
9208
+ dateStatus: EnumEventDateStatus.INVALID
9191
9209
  };
9192
9210
  }
9193
- let dateStatus = null;
9194
- if (endDateTime.isBefore(now)) {
9195
- dateStatus = EnumEventDateStatus.ENDED;
9196
- } else if (startDateTime.isBefore(now) && endDateTime.isAfter(now)) {
9197
- dateStatus = EnumEventDateStatus.STARTED;
9211
+ if (endDateTime.isBefore(startDateTime)) {
9212
+ return {
9213
+ ...dateTime,
9214
+ dateStatus: EnumEventDateStatus.INVALID
9215
+ };
9216
+ }
9217
+ let dateStatus;
9218
+ if (endDateTime.isAfter(now)) {
9219
+ if (startDateTime.isAfter(now)) {
9220
+ dateStatus = getFutureEventStatus(startDateTime, now);
9221
+ } else {
9222
+ dateStatus = EnumEventDateStatus.STARTED;
9223
+ }
9198
9224
  } else {
9199
- dateStatus = getFutureEventStatus(startDateTime, now);
9225
+ dateStatus = EnumEventDateStatus.ENDED;
9200
9226
  }
9201
9227
  return {
9202
9228
  ...dateTime,
9203
9229
  dateStatus
9204
9230
  };
9205
9231
  }
9232
+ var dateTimeStatusFilter = {
9233
+ dateTime: { $ne: [], $type: "array" },
9234
+ deletedAt: null
9235
+ };
9236
+ var CURSOR_BATCH_SIZE = 50;
9237
+ function hasDateTimeStatusChanges(stored, updated) {
9238
+ if (stored.length !== updated.length) {
9239
+ return true;
9240
+ }
9241
+ return stored.some(
9242
+ (slot, index) => slot.dateStatus !== updated[index].dateStatus
9243
+ );
9244
+ }
9245
+ async function updateModelDateTimeStatuses(model, now) {
9246
+ let updated = 0;
9247
+ const cursor = model.find(dateTimeStatusFilter).select({ _id: 1, dateTime: 1 }).lean().cursor({ batchSize: CURSOR_BATCH_SIZE });
9248
+ let bulkOps = [];
9249
+ const flushBulkWrites = async () => {
9250
+ if (!bulkOps.length) {
9251
+ return;
9252
+ }
9253
+ await model.bulkWrite(bulkOps);
9254
+ updated += bulkOps.length;
9255
+ bulkOps = [];
9256
+ };
9257
+ try {
9258
+ for await (const doc of cursor) {
9259
+ const dateTime = doc.dateTime.map(
9260
+ (slot) => updateSingleDateTimeStatus(slot, now)
9261
+ );
9262
+ if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
9263
+ continue;
9264
+ }
9265
+ bulkOps.push({
9266
+ updateOne: {
9267
+ filter: { _id: doc._id },
9268
+ update: { $set: { dateTime } }
9269
+ }
9270
+ });
9271
+ if (bulkOps.length >= CURSOR_BATCH_SIZE) {
9272
+ await flushBulkWrites();
9273
+ }
9274
+ }
9275
+ await flushBulkWrites();
9276
+ } finally {
9277
+ await cursor.close().catch(() => void 0);
9278
+ }
9279
+ return updated;
9280
+ }
9281
+ async function updateAllEventDateTimeStatuses() {
9282
+ const now = (0, import_dayjs2.default)();
9283
+ const [eventCount, marketCount] = await Promise.all([
9284
+ updateModelDateTimeStatuses(EventModel, now),
9285
+ updateModelDateTimeStatuses(
9286
+ GoogleImportedMarketModel,
9287
+ now
9288
+ )
9289
+ ]);
9290
+ console.log(
9291
+ `\u2705 Event dateTime statuses updated: events=${eventCount} changed, google imported markets=${marketCount} changed`
9292
+ );
9293
+ }
9294
+
9295
+ // src/service/event/findEventOrImportedMarketById.ts
9296
+ async function findEventOrImportedMarketById(resourceId) {
9297
+ if (!resourceId) {
9298
+ return null;
9299
+ }
9300
+ const normalizedId = convertObjectIdsToStrings(resourceId);
9301
+ const [eventDoc, googleImportedDoc] = await Promise.all([
9302
+ EventModel.findById(normalizedId).select("_id name").lean().exec(),
9303
+ GoogleImportedMarketModel.findById(normalizedId).select("_id name").lean().exec()
9304
+ ]);
9305
+ return eventDoc ?? googleImportedDoc;
9306
+ }
9206
9307
 
9207
9308
  // src/service/relations.ts
9208
9309
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
@@ -9235,6 +9336,7 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
9235
9336
  saveNotificationsInDb,
9236
9337
  sendPushNotifications,
9237
9338
  updateAdStatuses,
9339
+ updateAllEventDateTimeStatuses,
9238
9340
  updateRelationDatesToUnavailable,
9239
9341
  updateSingleDateTimeStatus,
9240
9342
  updateVendorBasedOnUserLicense