bulltrackers-module 1.0.424 → 1.0.426
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.
|
@@ -573,6 +573,24 @@ async function getUserPortfolio(req, res, dependencies, config) {
|
|
|
573
573
|
const devOverride = await getDevOverride(db, userCid, config, logger);
|
|
574
574
|
const isImpersonating = devOverride && devOverride.impersonateCid && effectiveCid !== Number(userCid);
|
|
575
575
|
|
|
576
|
+
// If impersonating, check if the effective CID is a Popular Investor
|
|
577
|
+
// PIs store data in pi_portfolios_overall, not signed_in_users
|
|
578
|
+
if (isImpersonating) {
|
|
579
|
+
const rankEntry = await checkIfUserIsPI(db, effectiveCid, config, logger);
|
|
580
|
+
if (rankEntry) {
|
|
581
|
+
// This is a PI being impersonated - they don't have signed_in_users portfolio data
|
|
582
|
+
// Return a helpful error indicating they should use the PI profile endpoint instead
|
|
583
|
+
return res.status(404).json({
|
|
584
|
+
error: "Popular Investor account",
|
|
585
|
+
message: `CID ${effectiveCid} is a Popular Investor. Use /user/me/pi-personalized-metrics or /user/pi/${effectiveCid}/profile instead.`,
|
|
586
|
+
effectiveCid: effectiveCid,
|
|
587
|
+
isImpersonating: true,
|
|
588
|
+
isPopularInvestor: true,
|
|
589
|
+
suggestedEndpoint: `/user/me/pi-personalized-metrics?userCid=${userCid}`
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
576
594
|
const { signedInUsersCollection } = config;
|
|
577
595
|
const CANARY_BLOCK_ID = '19M';
|
|
578
596
|
const today = new Date().toISOString().split('T')[0];
|
|
@@ -614,12 +632,15 @@ async function getUserPortfolio(req, res, dependencies, config) {
|
|
|
614
632
|
}
|
|
615
633
|
|
|
616
634
|
if (!portfolioData) {
|
|
617
|
-
return res.status(404).json({
|
|
635
|
+
return res.status(404).json({
|
|
636
|
+
error: "Portfolio data not found in any part document",
|
|
637
|
+
effectiveCid: effectiveCid,
|
|
638
|
+
isImpersonating: isImpersonating || false
|
|
639
|
+
});
|
|
618
640
|
}
|
|
619
641
|
|
|
620
642
|
// Apply dev override to AggregatedMirrors if dev override is active
|
|
621
|
-
|
|
622
|
-
const devOverride = await getDevOverride(db, userCid, config, logger);
|
|
643
|
+
// Note: devOverride is already available from earlier in the function (line 573)
|
|
623
644
|
if (devOverride && devOverride.enabled && devOverride.fakeCopiedPIs.length > 0 && portfolioData.AggregatedMirrors) {
|
|
624
645
|
logger.log('INFO', `[getUserPortfolio] Applying DEV OVERRIDE to AggregatedMirrors for user ${userCid}`);
|
|
625
646
|
|
|
@@ -973,13 +994,17 @@ async function autoGenerateWatchlist(req, res, dependencies, config) {
|
|
|
973
994
|
}
|
|
974
995
|
|
|
975
996
|
try {
|
|
997
|
+
// Check for dev override impersonation (for computation lookup)
|
|
998
|
+
const { getEffectiveCid, getCopiedPIsWithDevOverride } = require('./dev_helpers');
|
|
999
|
+
const effectiveCid = await getEffectiveCid(db, userCid, config, logger);
|
|
1000
|
+
|
|
976
1001
|
let copiedPIs = [];
|
|
977
1002
|
let dataSource = 'unknown';
|
|
978
1003
|
let isDevOverride = false;
|
|
979
1004
|
const today = new Date().toISOString().split('T')[0];
|
|
980
1005
|
|
|
981
1006
|
// === DEV OVERRIDE CHECK (for developer accounts) ===
|
|
982
|
-
|
|
1007
|
+
// Note: Use actual userCid for dev override check (dev override is about what PIs the developer "copies")
|
|
983
1008
|
const devResult = await getCopiedPIsWithDevOverride(db, userCid, config, logger);
|
|
984
1009
|
if (devResult.isDevOverride) {
|
|
985
1010
|
copiedPIs = devResult.copiedPIs;
|
|
@@ -990,12 +1015,14 @@ async function autoGenerateWatchlist(req, res, dependencies, config) {
|
|
|
990
1015
|
|
|
991
1016
|
// === PRIMARY: Try to fetch from computation (cheaper/faster) ===
|
|
992
1017
|
// Only if dev override is not active
|
|
1018
|
+
// Use effectiveCid for computation lookup (to support impersonation)
|
|
993
1019
|
if (!isDevOverride) {
|
|
994
1020
|
const insightsCollection = config.unifiedInsightsCollection || 'unified_insights';
|
|
995
1021
|
const category = 'signed_in_user';
|
|
996
1022
|
const computationName = 'SignedInUserCopiedPIs';
|
|
997
1023
|
|
|
998
1024
|
// Try to find latest computation date (with fallback)
|
|
1025
|
+
// Use effectiveCid for lookup (supports impersonation)
|
|
999
1026
|
const resultsSub = config.resultsSubcollection || 'results';
|
|
1000
1027
|
const compsSub = config.computationsSubcollection || 'computations';
|
|
1001
1028
|
const computationDate = await findLatestComputationDate(
|
|
@@ -1005,7 +1032,7 @@ async function autoGenerateWatchlist(req, res, dependencies, config) {
|
|
|
1005
1032
|
compsSub,
|
|
1006
1033
|
category,
|
|
1007
1034
|
computationName,
|
|
1008
|
-
|
|
1035
|
+
effectiveCid,
|
|
1009
1036
|
30
|
|
1010
1037
|
);
|
|
1011
1038
|
|