@timardex/cluemart-server-shared 2.2.0 → 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;
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;
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,