bulltrackers-module 1.0.549 → 1.0.551
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/functions/alert-system/helpers/alert_helpers.js +1 -1
- package/functions/alert-system/helpers/alert_type_registry.js +11 -1
- package/functions/generic-api/user-api/helpers/core/path_resolution_helpers.js +43 -15
- package/functions/generic-api/user-api/helpers/watchlist/watchlist_management_helpers.js +15 -2
- package/package.json +1 -1
|
@@ -120,7 +120,7 @@ async function findSubscriptionsForPI(db, logger, piCid, alertTypeId) {
|
|
|
120
120
|
'NewSectorExposure': 'newSector',
|
|
121
121
|
'PositionInvestedIncrease': 'increasedPositionSize',
|
|
122
122
|
'NewSocialPost': 'newSocialPost',
|
|
123
|
-
'
|
|
123
|
+
'TestSystemProbe': 'increasedRisk' // Hack: Map to 'increasedRisk' so you receive it if you have Risk alerts on
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
const configKey = computationToConfigKey[alertTypeId];
|
|
@@ -53,7 +53,17 @@ const ALERT_TYPES = {
|
|
|
53
53
|
messageTemplate: '{piUsername} posted a new update: {title}',
|
|
54
54
|
severity: 'low',
|
|
55
55
|
enabled: true
|
|
56
|
-
}
|
|
56
|
+
},
|
|
57
|
+
testSystemProbe: {
|
|
58
|
+
id: 'testSystemProbe',
|
|
59
|
+
name: 'Test System Probe',
|
|
60
|
+
description: 'Always-on debug alert',
|
|
61
|
+
computationName: 'TestSystemProbe', // Must match the class name above
|
|
62
|
+
category: 'alerts',
|
|
63
|
+
messageTemplate: 'Probe Triggered for {status} at {timestamp}', // Uses keys from the result object
|
|
64
|
+
severity: 'info',
|
|
65
|
+
enabled: true
|
|
66
|
+
},
|
|
57
67
|
};
|
|
58
68
|
|
|
59
69
|
/**
|
|
@@ -285,11 +285,22 @@ async function readWithMigration(db, category, subcategory, params, options = {}
|
|
|
285
285
|
try {
|
|
286
286
|
if (isCollection) {
|
|
287
287
|
// Collection path must have odd number of segments
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
288
|
+
if (documentId) {
|
|
289
|
+
// Read specific document from collection
|
|
290
|
+
const docRef = db.collection(newPath).doc(documentId);
|
|
291
|
+
const doc = await docRef.get();
|
|
292
|
+
if (doc.exists) {
|
|
293
|
+
if (logger) logger.log('INFO', `[readWithMigration] Found document in new path: ${docRef.path}`);
|
|
294
|
+
return { data: doc.data(), exists: true, source: 'new', path: docRef.path };
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
// Read entire collection
|
|
298
|
+
const collectionRef = db.collection(newPath);
|
|
299
|
+
const snapshot = await collectionRef.get();
|
|
300
|
+
if (!snapshot.empty) {
|
|
301
|
+
if (logger) logger.log('INFO', `[readWithMigration] Found data in new path: ${newPath}`);
|
|
302
|
+
return { snapshot, source: 'new', path: newPath };
|
|
303
|
+
}
|
|
293
304
|
}
|
|
294
305
|
} else {
|
|
295
306
|
// Document path: if newPath has even segments, it's already a document path
|
|
@@ -345,17 +356,34 @@ async function readWithMigration(db, category, subcategory, params, options = {}
|
|
|
345
356
|
legacyPath = legacyPath.replace(/{version}/g, params.version || '{version}');
|
|
346
357
|
|
|
347
358
|
if (isCollection) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
359
|
+
if (documentId) {
|
|
360
|
+
// Read specific document from legacy collection
|
|
361
|
+
const legacyDocRef = db.collection(legacyPath).doc(documentId);
|
|
362
|
+
const legacyDoc = await legacyDocRef.get();
|
|
363
|
+
if (legacyDoc.exists) {
|
|
364
|
+
if (logger) logger.log('INFO', `[readWithMigration] Found document in legacy path: ${legacyDocRef.path}, will migrate`);
|
|
365
|
+
|
|
366
|
+
// Auto-migrate if new path is available
|
|
367
|
+
if (newPath) {
|
|
368
|
+
await migrateDocumentData(db, legacyDoc, newPath, documentId, logger);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return { data: legacyDoc.data(), exists: true, source: 'legacy', path: legacyDocRef.path, migrated: !!newPath };
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
// Read entire legacy collection
|
|
375
|
+
const legacyCollectionRef = db.collection(legacyPath);
|
|
376
|
+
const legacySnapshot = await legacyCollectionRef.get();
|
|
377
|
+
if (!legacySnapshot.empty) {
|
|
378
|
+
if (logger) logger.log('INFO', `[readWithMigration] Found data in legacy path: ${legacyPath}, will migrate`);
|
|
379
|
+
|
|
380
|
+
// Auto-migrate if new path is available
|
|
381
|
+
if (newPath) {
|
|
382
|
+
await migrateCollectionData(db, legacySnapshot, newPath, dataType, logger);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return { snapshot: legacySnapshot, source: 'legacy', path: legacyPath, migrated: !!newPath };
|
|
356
386
|
}
|
|
357
|
-
|
|
358
|
-
return { snapshot: legacySnapshot, source: 'legacy', path: legacyPath, migrated: !!newPath };
|
|
359
387
|
}
|
|
360
388
|
} else {
|
|
361
389
|
const legacyDocRef = documentId
|
|
@@ -225,11 +225,24 @@ async function updateWatchlist(req, res, dependencies, config) {
|
|
|
225
225
|
}
|
|
226
226
|
);
|
|
227
227
|
|
|
228
|
-
if (!readResult
|
|
228
|
+
if (!readResult) {
|
|
229
229
|
return res.status(404).json({ error: "Watchlist not found" });
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
// Handle both document read (with data) and collection read (with snapshot)
|
|
233
|
+
let existingData;
|
|
234
|
+
if (readResult.data) {
|
|
235
|
+
existingData = readResult.data;
|
|
236
|
+
} else if (readResult.snapshot && !readResult.snapshot.empty) {
|
|
237
|
+
// If we got a snapshot, find the specific document
|
|
238
|
+
const doc = readResult.snapshot.docs.find(d => d.id === id);
|
|
239
|
+
if (!doc) {
|
|
240
|
+
return res.status(404).json({ error: "Watchlist not found" });
|
|
241
|
+
}
|
|
242
|
+
existingData = doc.data();
|
|
243
|
+
} else {
|
|
244
|
+
return res.status(404).json({ error: "Watchlist not found" });
|
|
245
|
+
}
|
|
233
246
|
|
|
234
247
|
// Verify ownership
|
|
235
248
|
if (existingData.createdBy !== Number(userCid)) {
|