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