@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.
@@ -127,9 +127,8 @@ declare function publishNotificationEvents(userId: ObjectId, pubsub: Notificatio
127
127
  * is provided) publishes GraphQL subscription events for each affected user.
128
128
  *
129
129
  * Errors are logged and swallowed; this function never throws. Instead it
130
- * returns `false` when notifications were not confirmed (an error was thrown,
131
- * or `saveNotificationsInDb` failed to persist any rows for a non-empty
132
- * `userIds`), so callers can gate success logs/metrics on the result.
130
+ * returns `false` when notifications were not confirmed, so callers can gate
131
+ * success logs/metrics on the result.
133
132
  */
134
133
  declare function notifyUsers({ payload, pubsub, }: {
135
134
  payload: SchemaCreateBulkNotificationInput;
@@ -127,9 +127,8 @@ declare function publishNotificationEvents(userId: ObjectId, pubsub: Notificatio
127
127
  * is provided) publishes GraphQL subscription events for each affected user.
128
128
  *
129
129
  * Errors are logged and swallowed; this function never throws. Instead it
130
- * returns `false` when notifications were not confirmed (an error was thrown,
131
- * or `saveNotificationsInDb` failed to persist any rows for a non-empty
132
- * `userIds`), so callers can gate success logs/metrics on the result.
130
+ * returns `false` when notifications were not confirmed, so callers can gate
131
+ * success logs/metrics on the result.
133
132
  */
134
133
  declare function notifyUsers({ payload, pubsub, }: {
135
134
  payload: SchemaCreateBulkNotificationInput;
@@ -10,7 +10,7 @@ import {
10
10
  PushTokenModel,
11
11
  UserModel,
12
12
  VendorModel
13
- } from "../chunk-HLRUWJLN.mjs";
13
+ } from "../chunk-ZKHRT2PV.mjs";
14
14
  import "../chunk-6PNG5BI5.mjs";
15
15
 
16
16
  // src/service/promoCode/constants.ts
@@ -39,25 +39,24 @@ import { createAffiliateReward } from "@timardex/cluemart-shared/utils";
39
39
  // src/service/saveNotificationsInDb.ts
40
40
  async function saveNotificationsInDb(payload) {
41
41
  const { data, message, title, type, userIds } = payload;
42
- console.log("NOTIFICATION DATA", JSON.stringify(payload, null, 2));
42
+ const notifications = userIds.map((userId) => ({
43
+ data,
44
+ isRead: false,
45
+ message,
46
+ title,
47
+ type,
48
+ userId
49
+ }));
43
50
  try {
44
- const notifications = userIds.map((userId) => ({
45
- data,
46
- isRead: false,
47
- message,
48
- title,
49
- type,
50
- userId
51
- }));
52
51
  await NotificationModel.insertMany(notifications);
53
- console.log(
54
- `Created ${notifications.length} notifications for ${userIds.length} users`
55
- );
56
- return [...new Set(userIds)];
57
52
  } catch (error) {
58
53
  console.error("Failed to create notifications:", error);
59
- return [];
54
+ throw error;
60
55
  }
56
+ console.log(
57
+ `Created ${notifications.length} notifications for ${userIds.length} users`
58
+ );
59
+ return [...new Set(userIds)];
61
60
  }
62
61
 
63
62
  // src/service/sendPushNotifications.ts
@@ -81,7 +80,7 @@ function createPushMessages({
81
80
  }
82
81
  messages.push({
83
82
  body: message,
84
- data: { ...data },
83
+ ...data ? { data: { ...data } } : {},
85
84
  sound: "tui.wav",
86
85
  title,
87
86
  to: token
@@ -136,7 +135,6 @@ async function sendPushNotifications({
136
135
  }) {
137
136
  const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
138
137
  const expoTokens = pushTokens.map((token) => token.token);
139
- if (!data) return;
140
138
  const { messages, invalidTokens } = createPushMessages({
141
139
  data,
142
140
  message,