@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.
@@ -52,7 +52,7 @@ import {
52
52
  termsAgreementSchema,
53
53
  userLicenseSchema,
54
54
  vendorProductTypeSchema
55
- } from "../chunk-HLRUWJLN.mjs";
55
+ } from "../chunk-ZKHRT2PV.mjs";
56
56
  export {
57
57
  AD_BILLING_CATALOG_COLLECTION_NAME,
58
58
  APP_SETTINGS_ID,
@@ -1118,16 +1118,24 @@ var GoogleImportedMarketModel = import_mongoose10.default.models.GoogleImportedM
1118
1118
  var import_cluemart_shared9 = require("@timardex/cluemart-shared");
1119
1119
  var import_mongoose11 = __toESM(require("mongoose"));
1120
1120
  var MongooseSchema7 = import_mongoose11.default.Schema;
1121
+ var notificationDataSchema = new MongooseSchema7(
1122
+ {
1123
+ resourceId: { required: true, type: String },
1124
+ resourceName: { required: true, type: String },
1125
+ resourceType: {
1126
+ enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
1127
+ required: true,
1128
+ type: String
1129
+ }
1130
+ },
1131
+ { _id: false }
1132
+ );
1121
1133
  var schema8 = new MongooseSchema7(
1122
1134
  {
1123
1135
  data: {
1124
- resourceId: { required: true, type: String },
1125
- resourceName: { required: true, type: String },
1126
- resourceType: {
1127
- enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
1128
- required: true,
1129
- type: String
1130
- }
1136
+ default: null,
1137
+ required: false,
1138
+ type: notificationDataSchema
1131
1139
  },
1132
1140
  isRead: { default: false, index: true, required: true, type: Boolean },
1133
1141
  message: { required: true, type: String },
@@ -2529,25 +2537,24 @@ var import_utils3 = require("@timardex/cluemart-shared/utils");
2529
2537
  // src/service/saveNotificationsInDb.ts
2530
2538
  async function saveNotificationsInDb(payload) {
2531
2539
  const { data, message, title, type, userIds } = payload;
2532
- console.log("NOTIFICATION DATA", JSON.stringify(payload, null, 2));
2540
+ const notifications = userIds.map((userId) => ({
2541
+ data,
2542
+ isRead: false,
2543
+ message,
2544
+ title,
2545
+ type,
2546
+ userId
2547
+ }));
2533
2548
  try {
2534
- const notifications = userIds.map((userId) => ({
2535
- data,
2536
- isRead: false,
2537
- message,
2538
- title,
2539
- type,
2540
- userId
2541
- }));
2542
2549
  await NotificationModel.insertMany(notifications);
2543
- console.log(
2544
- `Created ${notifications.length} notifications for ${userIds.length} users`
2545
- );
2546
- return [...new Set(userIds)];
2547
2550
  } catch (error) {
2548
2551
  console.error("Failed to create notifications:", error);
2549
- return [];
2552
+ throw error;
2550
2553
  }
2554
+ console.log(
2555
+ `Created ${notifications.length} notifications for ${userIds.length} users`
2556
+ );
2557
+ return [...new Set(userIds)];
2551
2558
  }
2552
2559
 
2553
2560
  // src/service/sendPushNotifications.ts
@@ -2571,7 +2578,7 @@ function createPushMessages({
2571
2578
  }
2572
2579
  messages.push({
2573
2580
  body: message,
2574
- data: { ...data },
2581
+ ...data ? { data: { ...data } } : {},
2575
2582
  sound: "tui.wav",
2576
2583
  title,
2577
2584
  to: token
@@ -2626,7 +2633,6 @@ async function sendPushNotifications({
2626
2633
  }) {
2627
2634
  const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
2628
2635
  const expoTokens = pushTokens.map((token) => token.token);
2629
- if (!data) return;
2630
2636
  const { messages, invalidTokens } = createPushMessages({
2631
2637
  data,
2632
2638
  message,
@@ -3145,6 +3151,10 @@ async function persistArchivedEventDates(eventId, slots) {
3145
3151
  // src/service/event/updateAllEventDateTimeStatuses.ts
3146
3152
  import_dayjs2.default.extend(import_customParseFormat.default);
3147
3153
  import_dayjs2.default.extend(import_isoWeek.default);
3154
+ var MANUAL_DATE_STATUSES = /* @__PURE__ */ new Set([
3155
+ import_cluemart_shared26.EnumEventDateStatus.CANCELED,
3156
+ import_cluemart_shared26.EnumEventDateStatus.RE_SCHEDULED
3157
+ ]);
3148
3158
  function getFutureEventStatus(startDateTime, now) {
3149
3159
  const hoursUntilStart = startDateTime.diff(now, "hour", true);
3150
3160
  if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
@@ -3165,6 +3175,9 @@ function getFutureEventStatus(startDateTime, now) {
3165
3175
  return import_cluemart_shared26.EnumEventDateStatus.UPCOMING;
3166
3176
  }
3167
3177
  function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
3178
+ if (MANUAL_DATE_STATUSES.has(dateTime.dateStatus)) {
3179
+ return dateTime;
3180
+ }
3168
3181
  const dateTimeFormat = `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`;
3169
3182
  const startDateTime = (0, import_dayjs2.default)(
3170
3183
  `${dateTime.startDate} ${dateTime.startTime}`,