@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.d.mts CHANGED
@@ -711,6 +711,11 @@ declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: E
711
711
  */
712
712
  declare function convertObjectIdsToStrings(obj: any): any;
713
713
 
714
+ /**
715
+ * Recomputes dateStatus for every dateTime slot on events and google imported markets.
716
+ */
717
+ declare function updateAllEventDateTimeStatuses(): Promise<void>;
718
+
714
719
  type EventOrMarket = Pick<EventListItemType, "_id" | "name"> | null;
715
720
  /**
716
721
  * This function attempts to find an Event or a Google Imported Market by the given resource ID.
@@ -734,4 +739,4 @@ declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | unde
734
739
  */
735
740
  declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationType["relationDates"], eventDateTime: DateTimeWithPriceType[] | undefined): SchemaRelationType["relationDates"];
736
741
 
737
- export { APP_SETTINGS_ID, AdModel, AppSettingModel, type AuthUser, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, NotificationModel, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, associatesSchema, baseResourceFields, connectToDatabase, convertObjectIdsToStrings, dateTimeSchema, didRemoveAnyEventDates, findEventOrImportedMarketById, locationGeoSchema, locationsSchema, refundPolicySchema, relationDatesSchema, resourceRelationsSchema, saveNotificationsInDb, sendPushNotifications, termsAgreementSchema, updateAdStatuses, updateRelationDatesToUnavailable, updateVendorBasedOnUserLicense, userLicenseSchema };
742
+ export { APP_SETTINGS_ID, AdModel, AppSettingModel, type AuthUser, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, NotificationModel, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, associatesSchema, baseResourceFields, connectToDatabase, convertObjectIdsToStrings, dateTimeSchema, didRemoveAnyEventDates, findEventOrImportedMarketById, locationGeoSchema, locationsSchema, refundPolicySchema, relationDatesSchema, resourceRelationsSchema, saveNotificationsInDb, sendPushNotifications, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateVendorBasedOnUserLicense, userLicenseSchema };
package/dist/index.d.ts CHANGED
@@ -711,6 +711,11 @@ declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: E
711
711
  */
712
712
  declare function convertObjectIdsToStrings(obj: any): any;
713
713
 
714
+ /**
715
+ * Recomputes dateStatus for every dateTime slot on events and google imported markets.
716
+ */
717
+ declare function updateAllEventDateTimeStatuses(): Promise<void>;
718
+
714
719
  type EventOrMarket = Pick<EventListItemType, "_id" | "name"> | null;
715
720
  /**
716
721
  * This function attempts to find an Event or a Google Imported Market by the given resource ID.
@@ -734,4 +739,4 @@ declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | unde
734
739
  */
735
740
  declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationType["relationDates"], eventDateTime: DateTimeWithPriceType[] | undefined): SchemaRelationType["relationDates"];
736
741
 
737
- export { APP_SETTINGS_ID, AdModel, AppSettingModel, type AuthUser, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, NotificationModel, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, associatesSchema, baseResourceFields, connectToDatabase, convertObjectIdsToStrings, dateTimeSchema, didRemoveAnyEventDates, findEventOrImportedMarketById, locationGeoSchema, locationsSchema, refundPolicySchema, relationDatesSchema, resourceRelationsSchema, saveNotificationsInDb, sendPushNotifications, termsAgreementSchema, updateAdStatuses, updateRelationDatesToUnavailable, updateVendorBasedOnUserLicense, userLicenseSchema };
742
+ export { APP_SETTINGS_ID, AdModel, AppSettingModel, type AuthUser, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, NotificationModel, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, associatesSchema, baseResourceFields, connectToDatabase, convertObjectIdsToStrings, dateTimeSchema, didRemoveAnyEventDates, findEventOrImportedMarketById, locationGeoSchema, locationsSchema, refundPolicySchema, relationDatesSchema, resourceRelationsSchema, saveNotificationsInDb, sendPushNotifications, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateVendorBasedOnUserLicense, userLicenseSchema };
package/dist/index.mjs CHANGED
@@ -3361,6 +3361,7 @@ var EnumEventDateStatus = /* @__PURE__ */ ((EnumEventDateStatus22) => {
3361
3361
  EnumEventDateStatus22["ENDED"] = "Ended";
3362
3362
  EnumEventDateStatus22["RE_SCHEDULED"] = "Rescheduled";
3363
3363
  EnumEventDateStatus22["CANCELED"] = "Canceled";
3364
+ EnumEventDateStatus22["INVALID"] = "Invalid";
3364
3365
  return EnumEventDateStatus22;
3365
3366
  })(EnumEventDateStatus || {});
3366
3367
  var EnumSubscriptionStatus = /* @__PURE__ */ ((EnumSubscriptionStatus22) => {
@@ -3477,6 +3478,8 @@ var gameScreenIdentifierList = [
3477
3478
  match: "/visitors"
3478
3479
  }
3479
3480
  ];
3481
+ var dateFormat = "DD-MM-YYYY";
3482
+ var timeFormat = "HH:mm";
3480
3483
  dayjs.extend(customParseFormat);
3481
3484
  dayjs.extend(utc);
3482
3485
  dayjs.extend(timezone);
@@ -5142,8 +5145,8 @@ var EVENT = gql`
5142
5145
  ${RELATION_DATES_FRAGMENT}
5143
5146
  `;
5144
5147
  var GET_EVENTS = gql`
5145
- query getEvents {
5146
- events {
5148
+ query getEvents($dateStatus: EnumEventDateStatus) {
5149
+ events(dateStatus: $dateStatus) {
5147
5150
  ...EventListItemFields
5148
5151
  }
5149
5152
  }
@@ -5169,24 +5172,49 @@ var GET_EVENTS_BY_REGION = gql`
5169
5172
  query getEventsByRegion(
5170
5173
  $region: String!
5171
5174
  $options: ResourcesByRegionOptions
5175
+ $dateStatus: EnumEventDateStatus
5172
5176
  ) {
5173
- eventsByRegion(region: $region, options: $options) {
5177
+ eventsByRegion(
5178
+ region: $region
5179
+ options: $options
5180
+ dateStatus: $dateStatus
5181
+ ) {
5174
5182
  ...EventListItemFields
5175
5183
  }
5176
5184
  }
5177
5185
  ${EVENT_LIST_ITEM}
5178
5186
  `;
5179
5187
  var SEARCH_EVENTS = gql`
5180
- query searchEvents($region: String, $search: String, $tags: [String]) {
5181
- eventsSearch(region: $region, search: $search, tags: $tags) {
5188
+ query searchEvents(
5189
+ $region: String
5190
+ $search: String
5191
+ $tags: [String]
5192
+ $dateStatus: EnumEventDateStatus
5193
+ ) {
5194
+ eventsSearch(
5195
+ region: $region
5196
+ search: $search
5197
+ tags: $tags
5198
+ dateStatus: $dateStatus
5199
+ ) {
5182
5200
  ...EventListItemFields
5183
5201
  }
5184
5202
  }
5185
5203
  ${EVENT_LIST_ITEM}
5186
5204
  `;
5187
5205
  var GET_EVENTS_NEAR_ME = gql`
5188
- query getEventsNearMe($latitude: Float!, $longitude: Float!, $radius: Int) {
5189
- eventsNearMe(latitude: $latitude, longitude: $longitude, radius: $radius) {
5206
+ query getEventsNearMe(
5207
+ $latitude: Float!
5208
+ $longitude: Float!
5209
+ $radius: Int
5210
+ $dateStatus: EnumEventDateStatus
5211
+ ) {
5212
+ eventsNearMe(
5213
+ latitude: $latitude
5214
+ longitude: $longitude
5215
+ radius: $radius
5216
+ dateStatus: $dateStatus
5217
+ ) {
5190
5218
  ...EventListItemFields
5191
5219
  }
5192
5220
  }
@@ -7859,6 +7887,8 @@ var schema3 = new MongooseSchema7(
7859
7887
  schema3.index({ "location.geo": "2dsphere" });
7860
7888
  schema3.index({ name: 1 });
7861
7889
  schema3.index({ region: 1 });
7890
+ schema3.index({ deletedAt: 1 });
7891
+ schema3.index({ "dateTime.dateStatus": 1 });
7862
7892
  var GoogleImportedMarketModel = mongoose7.models.GoogleImportedMarket || mongoose7.model("GoogleImportedMarket", schema3);
7863
7893
 
7864
7894
  // src/mongoose/Notification.ts
@@ -7896,7 +7926,7 @@ schema4.index({ isRead: 1, userId: 1 });
7896
7926
  schema4.index({ createdAt: -1, userId: 1 });
7897
7927
  var NotificationModel = mongoose8.models.Notification || mongoose8.model("Notification", schema4);
7898
7928
 
7899
- // node_modules/@timardex/cluemart-shared/dist/chunk-6B75Q67V.mjs
7929
+ // node_modules/@timardex/cluemart-shared/dist/chunk-4SNW63TJ.mjs
7900
7930
  var EnumOSPlatform2 = /* @__PURE__ */ ((EnumOSPlatform22) => {
7901
7931
  EnumOSPlatform22["ANDROID"] = "android";
7902
7932
  EnumOSPlatform22["IOS"] = "ios";
@@ -8405,6 +8435,8 @@ schema12.index({ region: 1 });
8405
8435
  schema12.index({ "location.geo": "2dsphere" });
8406
8436
  schema12.index({ tags: 1 });
8407
8437
  schema12.index({ "associates.email": 1 });
8438
+ schema12.index({ deletedAt: 1 });
8439
+ schema12.index({ "dateTime.dateStatus": 1 });
8408
8440
  var EventModel = mongoose16.models.Event || mongoose16.model("Event", schema12);
8409
8441
 
8410
8442
  // src/mongoose/Partner.ts
@@ -9085,7 +9117,134 @@ function convertObjectIdsToStrings(obj) {
9085
9117
  return obj;
9086
9118
  }
9087
9119
 
9088
- // src/service/event.ts
9120
+ // src/service/event/updateAllEventDateTimeStatuses.ts
9121
+ import dayjs2 from "dayjs";
9122
+ import customParseFormat2 from "dayjs/plugin/customParseFormat";
9123
+ import isoWeek from "dayjs/plugin/isoWeek";
9124
+ dayjs2.extend(customParseFormat2);
9125
+ dayjs2.extend(isoWeek);
9126
+ function getFutureEventStatus(startDateTime, now) {
9127
+ const hoursUntilStart = startDateTime.diff(now, "hour", true);
9128
+ if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
9129
+ return EnumEventDateStatus.STARTING_SOON;
9130
+ }
9131
+ if (startDateTime.isSame(now, "day")) {
9132
+ return EnumEventDateStatus.TODAY;
9133
+ }
9134
+ if (startDateTime.isSame(now.add(1, "day"), "day")) {
9135
+ return EnumEventDateStatus.TOMORROW;
9136
+ }
9137
+ if (startDateTime.isSame(now, "isoWeek")) {
9138
+ return EnumEventDateStatus.THIS_WEEK;
9139
+ }
9140
+ if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
9141
+ return EnumEventDateStatus.NEXT_WEEK;
9142
+ }
9143
+ return EnumEventDateStatus.UPCOMING;
9144
+ }
9145
+ function updateSingleDateTimeStatus(dateTime, now = dayjs2()) {
9146
+ const dateTimeFormat = `${dateFormat} ${timeFormat}`;
9147
+ const startDateTime = dayjs2(
9148
+ `${dateTime.startDate} ${dateTime.startTime}`,
9149
+ dateTimeFormat,
9150
+ true
9151
+ );
9152
+ const endDateTime = dayjs2(
9153
+ `${dateTime.endDate} ${dateTime.endTime}`,
9154
+ dateTimeFormat,
9155
+ true
9156
+ );
9157
+ if (!startDateTime.isValid() || !endDateTime.isValid()) {
9158
+ return {
9159
+ ...dateTime,
9160
+ dateStatus: EnumEventDateStatus.INVALID
9161
+ };
9162
+ }
9163
+ if (endDateTime.isBefore(startDateTime)) {
9164
+ return {
9165
+ ...dateTime,
9166
+ dateStatus: EnumEventDateStatus.INVALID
9167
+ };
9168
+ }
9169
+ let dateStatus;
9170
+ if (endDateTime.isAfter(now)) {
9171
+ if (startDateTime.isAfter(now)) {
9172
+ dateStatus = getFutureEventStatus(startDateTime, now);
9173
+ } else {
9174
+ dateStatus = EnumEventDateStatus.STARTED;
9175
+ }
9176
+ } else {
9177
+ dateStatus = EnumEventDateStatus.ENDED;
9178
+ }
9179
+ return {
9180
+ ...dateTime,
9181
+ dateStatus
9182
+ };
9183
+ }
9184
+ var dateTimeStatusFilter = {
9185
+ dateTime: { $ne: [], $type: "array" },
9186
+ deletedAt: null
9187
+ };
9188
+ var CURSOR_BATCH_SIZE = 50;
9189
+ function hasDateTimeStatusChanges(stored, updated) {
9190
+ if (stored.length !== updated.length) {
9191
+ return true;
9192
+ }
9193
+ return stored.some(
9194
+ (slot, index) => slot.dateStatus !== updated[index].dateStatus
9195
+ );
9196
+ }
9197
+ async function updateModelDateTimeStatuses(model, now) {
9198
+ let updated = 0;
9199
+ const cursor = model.find(dateTimeStatusFilter).select({ _id: 1, dateTime: 1 }).lean().cursor({ batchSize: CURSOR_BATCH_SIZE });
9200
+ let bulkOps = [];
9201
+ const flushBulkWrites = async () => {
9202
+ if (!bulkOps.length) {
9203
+ return;
9204
+ }
9205
+ await model.bulkWrite(bulkOps);
9206
+ updated += bulkOps.length;
9207
+ bulkOps = [];
9208
+ };
9209
+ try {
9210
+ for await (const doc of cursor) {
9211
+ const dateTime = doc.dateTime.map(
9212
+ (slot) => updateSingleDateTimeStatus(slot, now)
9213
+ );
9214
+ if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
9215
+ continue;
9216
+ }
9217
+ bulkOps.push({
9218
+ updateOne: {
9219
+ filter: { _id: doc._id },
9220
+ update: { $set: { dateTime } }
9221
+ }
9222
+ });
9223
+ if (bulkOps.length >= CURSOR_BATCH_SIZE) {
9224
+ await flushBulkWrites();
9225
+ }
9226
+ }
9227
+ await flushBulkWrites();
9228
+ } finally {
9229
+ await cursor.close().catch(() => void 0);
9230
+ }
9231
+ return updated;
9232
+ }
9233
+ async function updateAllEventDateTimeStatuses() {
9234
+ const now = dayjs2();
9235
+ const [eventCount, marketCount] = await Promise.all([
9236
+ updateModelDateTimeStatuses(EventModel, now),
9237
+ updateModelDateTimeStatuses(
9238
+ GoogleImportedMarketModel,
9239
+ now
9240
+ )
9241
+ ]);
9242
+ console.log(
9243
+ `\u2705 Event dateTime statuses updated: events=${eventCount} changed, google imported markets=${marketCount} changed`
9244
+ );
9245
+ }
9246
+
9247
+ // src/service/event/findEventOrImportedMarketById.ts
9089
9248
  async function findEventOrImportedMarketById(resourceId) {
9090
9249
  if (!resourceId) {
9091
9250
  return null;
@@ -9179,6 +9338,7 @@ export {
9179
9338
  sendPushNotifications,
9180
9339
  termsAgreementSchema,
9181
9340
  updateAdStatuses,
9341
+ updateAllEventDateTimeStatuses,
9182
9342
  updateRelationDatesToUnavailable,
9183
9343
  updateVendorBasedOnUserLicense,
9184
9344
  userLicenseSchema