@timardex/cluemart-server-shared 2.1.11 → 2.2.1

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
@@ -1012,9 +1012,8 @@ declare function publishNotificationEvents(userId: ObjectId, pubsub: Notificatio
1012
1012
  * is provided) publishes GraphQL subscription events for each affected user.
1013
1013
  *
1014
1014
  * Errors are logged and swallowed; this function never throws. Instead it
1015
- * returns `false` when notifications were not confirmed (an error was thrown,
1016
- * or `saveNotificationsInDb` failed to persist any rows for a non-empty
1017
- * `userIds`), so callers can gate success logs/metrics on the result.
1015
+ * returns `false` when notifications were not confirmed, so callers can gate
1016
+ * success logs/metrics on the result.
1018
1017
  */
1019
1018
  declare function notifyUsers({ payload, pubsub, }: {
1020
1019
  payload: SchemaCreateBulkNotificationInput;
@@ -1045,9 +1044,11 @@ declare function isValidObjectId(value: string): boolean;
1045
1044
  declare function convertObjectIdsToStrings(obj: any): any;
1046
1045
 
1047
1046
  /**
1048
- * Updates the dateStatus field for a single DateTimeType object based on the current date/time
1047
+ * Updates the dateStatus field for a single DateTimeType object based on the current date/time.
1048
+ * Manual statuses (CANCELED, RE_SCHEDULED) are preserved and returned as-is.
1049
1049
  * @param dateTime The date-time object to update
1050
- * @returns A new object with updated dateStatus value
1050
+ * @returns A new object with an updated dateStatus value, or the original
1051
+ * object when the stored status is a manual override
1051
1052
  */
1052
1053
  declare function updateSingleDateTimeStatus<T extends DateTimeType>(dateTime: T, now?: dayjs.Dayjs): T;
1053
1054
  /**
package/dist/index.d.ts CHANGED
@@ -1012,9 +1012,8 @@ declare function publishNotificationEvents(userId: ObjectId, pubsub: Notificatio
1012
1012
  * is provided) publishes GraphQL subscription events for each affected user.
1013
1013
  *
1014
1014
  * Errors are logged and swallowed; this function never throws. Instead it
1015
- * returns `false` when notifications were not confirmed (an error was thrown,
1016
- * or `saveNotificationsInDb` failed to persist any rows for a non-empty
1017
- * `userIds`), so callers can gate success logs/metrics on the result.
1015
+ * returns `false` when notifications were not confirmed, so callers can gate
1016
+ * success logs/metrics on the result.
1018
1017
  */
1019
1018
  declare function notifyUsers({ payload, pubsub, }: {
1020
1019
  payload: SchemaCreateBulkNotificationInput;
@@ -1045,9 +1044,11 @@ declare function isValidObjectId(value: string): boolean;
1045
1044
  declare function convertObjectIdsToStrings(obj: any): any;
1046
1045
 
1047
1046
  /**
1048
- * Updates the dateStatus field for a single DateTimeType object based on the current date/time
1047
+ * Updates the dateStatus field for a single DateTimeType object based on the current date/time.
1048
+ * Manual statuses (CANCELED, RE_SCHEDULED) are preserved and returned as-is.
1049
1049
  * @param dateTime The date-time object to update
1050
- * @returns A new object with updated dateStatus value
1050
+ * @returns A new object with an updated dateStatus value, or the original
1051
+ * object when the stored status is a manual override
1051
1052
  */
1052
1053
  declare function updateSingleDateTimeStatus<T extends DateTimeType>(dateTime: T, now?: dayjs.Dayjs): T;
1053
1054
  /**
package/dist/index.mjs CHANGED
@@ -1083,16 +1083,24 @@ import {
1083
1083
  } from "@timardex/cluemart-shared";
1084
1084
  import mongoose11 from "mongoose";
1085
1085
  var MongooseSchema7 = mongoose11.Schema;
1086
+ var notificationDataSchema = new MongooseSchema7(
1087
+ {
1088
+ resourceId: { required: true, type: String },
1089
+ resourceName: { required: true, type: String },
1090
+ resourceType: {
1091
+ enum: Object.values(EnumNotificationResourceType),
1092
+ required: true,
1093
+ type: String
1094
+ }
1095
+ },
1096
+ { _id: false }
1097
+ );
1086
1098
  var schema8 = new MongooseSchema7(
1087
1099
  {
1088
1100
  data: {
1089
- resourceId: { required: true, type: String },
1090
- resourceName: { required: true, type: String },
1091
- resourceType: {
1092
- enum: Object.values(EnumNotificationResourceType),
1093
- required: true,
1094
- type: String
1095
- }
1101
+ default: null,
1102
+ required: false,
1103
+ type: notificationDataSchema
1096
1104
  },
1097
1105
  isRead: { default: false, index: true, required: true, type: Boolean },
1098
1106
  message: { required: true, type: String },
@@ -2539,25 +2547,24 @@ import { createAffiliateReward } from "@timardex/cluemart-shared/utils";
2539
2547
  // src/service/saveNotificationsInDb.ts
2540
2548
  async function saveNotificationsInDb(payload) {
2541
2549
  const { data, message, title, type, userIds } = payload;
2542
- console.log("NOTIFICATION DATA", JSON.stringify(payload, null, 2));
2550
+ const notifications = userIds.map((userId) => ({
2551
+ data,
2552
+ isRead: false,
2553
+ message,
2554
+ title,
2555
+ type,
2556
+ userId
2557
+ }));
2543
2558
  try {
2544
- const notifications = userIds.map((userId) => ({
2545
- data,
2546
- isRead: false,
2547
- message,
2548
- title,
2549
- type,
2550
- userId
2551
- }));
2552
2559
  await NotificationModel.insertMany(notifications);
2553
- console.log(
2554
- `Created ${notifications.length} notifications for ${userIds.length} users`
2555
- );
2556
- return [...new Set(userIds)];
2557
2560
  } catch (error) {
2558
2561
  console.error("Failed to create notifications:", error);
2559
- return [];
2562
+ throw error;
2560
2563
  }
2564
+ console.log(
2565
+ `Created ${notifications.length} notifications for ${userIds.length} users`
2566
+ );
2567
+ return [...new Set(userIds)];
2561
2568
  }
2562
2569
 
2563
2570
  // src/service/sendPushNotifications.ts
@@ -2581,7 +2588,7 @@ function createPushMessages({
2581
2588
  }
2582
2589
  messages.push({
2583
2590
  body: message,
2584
- data: { ...data },
2591
+ ...data ? { data: { ...data } } : {},
2585
2592
  sound: "tui.wav",
2586
2593
  title,
2587
2594
  to: token
@@ -2636,7 +2643,6 @@ async function sendPushNotifications({
2636
2643
  }) {
2637
2644
  const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
2638
2645
  const expoTokens = pushTokens.map((token) => token.token);
2639
- if (!data) return;
2640
2646
  const { messages, invalidTokens } = createPushMessages({
2641
2647
  data,
2642
2648
  message,
@@ -3178,6 +3184,10 @@ async function persistArchivedEventDates(eventId, slots) {
3178
3184
  // src/service/event/updateAllEventDateTimeStatuses.ts
3179
3185
  dayjs2.extend(customParseFormat);
3180
3186
  dayjs2.extend(isoWeek);
3187
+ var MANUAL_DATE_STATUSES = /* @__PURE__ */ new Set([
3188
+ EnumEventDateStatus7.CANCELED,
3189
+ EnumEventDateStatus7.RE_SCHEDULED
3190
+ ]);
3181
3191
  function getFutureEventStatus(startDateTime, now) {
3182
3192
  const hoursUntilStart = startDateTime.diff(now, "hour", true);
3183
3193
  if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
@@ -3198,6 +3208,9 @@ function getFutureEventStatus(startDateTime, now) {
3198
3208
  return EnumEventDateStatus7.UPCOMING;
3199
3209
  }
3200
3210
  function updateSingleDateTimeStatus(dateTime, now = dayjs2()) {
3211
+ if (MANUAL_DATE_STATUSES.has(dateTime.dateStatus)) {
3212
+ return dateTime;
3213
+ }
3201
3214
  const dateTimeFormat = `${dateFormat} ${timeFormat}`;
3202
3215
  const startDateTime = dayjs2(
3203
3216
  `${dateTime.startDate} ${dateTime.startTime}`,