bulltrackers-module 1.0.618 → 1.0.619

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.
@@ -2239,7 +2239,28 @@ const autoGenerateWatchlist = async (db, userId) => {
2239
2239
  }
2240
2240
  }
2241
2241
 
2242
- if (copiedPIs.length === 0) return { count: 0, message: "No copied PIs found" };
2242
+ const totalCopied = copiedPIs.length;
2243
+
2244
+ // If no copied PIs, send notification and return early
2245
+ if (totalCopied === 0) {
2246
+ const notificationId = `watchlist_auto_gen_${Date.now()}_${userId}`;
2247
+ await db.collection('SignedInUsers').doc(userId).collection('notifications').doc(notificationId).set({
2248
+ id: notificationId,
2249
+ type: 'watchlist_auto_generate',
2250
+ subType: 'info',
2251
+ title: 'Watchlist Auto-Generation',
2252
+ message: 'No copied Popular Investors found. Your watchlist is already up-to-date with all your copied PIs.',
2253
+ read: false,
2254
+ timestamp: FieldValue.serverTimestamp(),
2255
+ createdAt: FieldValue.serverTimestamp(),
2256
+ metadata: {
2257
+ userCid: Number(userId),
2258
+ generated: 0,
2259
+ totalCopied: 0
2260
+ }
2261
+ });
2262
+ return { success: true, generated: 0, totalCopied: 0, message: "No copied PIs found - watchlist is up-to-date" };
2263
+ }
2243
2264
 
2244
2265
  // 2. Build Watchlist Items
2245
2266
  const items = await Promise.all(copiedPIs.map(async (pi) => {
@@ -2270,13 +2291,44 @@ const autoGenerateWatchlist = async (db, userId) => {
2270
2291
  items,
2271
2292
  isAutoGenerated: true
2272
2293
  };
2273
-
2294
+
2295
+ let wasUpdate = false;
2274
2296
  if (!autoSnap.empty) {
2275
2297
  instruction = 'update';
2276
2298
  payload.id = autoSnap.docs[0].id;
2299
+ wasUpdate = true;
2277
2300
  }
2278
2301
 
2279
- return await manageUserWatchlist(db, userId, instruction, payload);
2302
+ const result = await manageUserWatchlist(db, userId, instruction, payload);
2303
+ const generated = items.length;
2304
+
2305
+ // 4. Send notification with proper text
2306
+ const notificationId = `watchlist_auto_gen_${Date.now()}_${userId}`;
2307
+ let notificationMessage;
2308
+ if (wasUpdate) {
2309
+ notificationMessage = `Updated your watchlist with ${generated} Popular Investor${generated !== 1 ? 's' : ''} from ${totalCopied} copied PI${totalCopied !== 1 ? 's' : ''}.`;
2310
+ } else {
2311
+ notificationMessage = `Successfully generated watchlist with ${generated} Popular Investor${generated !== 1 ? 's' : ''} from ${totalCopied} copied PI${totalCopied !== 1 ? 's' : ''}.`;
2312
+ }
2313
+
2314
+ await db.collection('SignedInUsers').doc(userId).collection('notifications').doc(notificationId).set({
2315
+ id: notificationId,
2316
+ type: 'watchlist_auto_generate',
2317
+ subType: 'success',
2318
+ title: 'Watchlist Auto-Generation',
2319
+ message: notificationMessage,
2320
+ read: false,
2321
+ timestamp: FieldValue.serverTimestamp(),
2322
+ createdAt: FieldValue.serverTimestamp(),
2323
+ metadata: {
2324
+ userCid: Number(userId),
2325
+ generated: generated,
2326
+ totalCopied: totalCopied,
2327
+ wasUpdate: wasUpdate
2328
+ }
2329
+ });
2330
+
2331
+ return { success: true, generated: generated, totalCopied: totalCopied, message: notificationMessage };
2280
2332
  };
2281
2333
 
2282
2334
  // ==========================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.618",
3
+ "version": "1.0.619",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [