bulltrackers-module 1.0.671 → 1.0.673

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.
@@ -2049,6 +2049,7 @@ const fetchUserRecommendations = async (db, userId) => {
2049
2049
 
2050
2050
  const fetchTrendingPopularInvestors = async (db) => {
2051
2051
  // Path: /unified_insights/{DATE}/results/popular-investor/computations/TrendingPopularInvestors
2052
+ // Simple fetch - data exists in pointer document (small size, not compressed/sharded)
2052
2053
  const today = new Date().toISOString().split('T')[0];
2053
2054
  try {
2054
2055
  const result = await getComputationResults(db, 'TrendingPopularInvestors', today);
@@ -2060,6 +2061,7 @@ const fetchTrendingPopularInvestors = async (db) => {
2060
2061
  };
2061
2062
 
2062
2063
  const fetchPopularInvestorCategories = async (db) => {
2064
+ // Data exists compressed in pointer document at /unified_insights/{DATE}/results/popular-investor/computations/PopularInvestorCategories
2063
2065
  const today = new Date().toISOString().split('T')[0];
2064
2066
  try {
2065
2067
  const result = await getComputationResults(db, 'PopularInvestorCategories', today);
@@ -209,11 +209,77 @@ router.get('/computations', async (req, res) => {
209
209
  const results = {};
210
210
  for (const compName of computationNames) {
211
211
  try {
212
- const data = await getComputationResults(db, compName, targetDate, userId);
212
+ let data = await getComputationResults(db, compName, targetDate, userId);
213
+
214
+ // For RecommendedPopularInvestors: Ensure data contains the signed-in user's CID
215
+ // If not found, look back up to 7 days to find this specific user's data
216
+ if (compName === 'RecommendedPopularInvestors' && mode === 'latest') {
217
+ const userCidStr = String(userId);
218
+ let foundUserData = false;
219
+
220
+ // Check if current result contains this user's data
221
+ if (data && typeof data === 'object') {
222
+ // For standard mode: data is { [userId]: recommendations[] }
223
+ if (data[userCidStr] && Array.isArray(data[userCidStr])) {
224
+ foundUserData = true;
225
+ }
226
+ // For page mode: data is array of { date, data: {...} }
227
+ else if (Array.isArray(data) && data.length > 0) {
228
+ // Check if any entry has this user's data
229
+ for (const entry of data) {
230
+ if (entry.data && entry.data[userCidStr]) {
231
+ foundUserData = true;
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ }
237
+
238
+ // If user's data not found, look back up to 7 days
239
+ if (!foundUserData) {
240
+ for (let i = 1; i <= 7; i++) {
241
+ const checkDate = new Date(targetDate);
242
+ checkDate.setDate(checkDate.getDate() - i);
243
+ const dateKey = checkDate.toISOString().split('T')[0];
244
+
245
+ try {
246
+ const backData = await getComputationResults(db, compName, dateKey, userId);
247
+ if (backData && typeof backData === 'object') {
248
+ // Check if this date has the user's data
249
+ if (backData[userCidStr] && Array.isArray(backData[userCidStr])) {
250
+ data = backData;
251
+ foundUserData = true;
252
+ break;
253
+ }
254
+ // For page mode
255
+ else if (Array.isArray(backData) && backData.length > 0) {
256
+ for (const entry of backData) {
257
+ if (entry.data && entry.data[userCidStr]) {
258
+ data = backData;
259
+ foundUserData = true;
260
+ break;
261
+ }
262
+ }
263
+ if (foundUserData) break;
264
+ }
265
+ }
266
+ } catch (e) {
267
+ // Continue to next date
268
+ }
269
+ }
270
+ }
271
+
272
+ // Only return data if it contains this user's recommendations
273
+ if (!foundUserData) {
274
+ results[compName] = null;
275
+ continue;
276
+ }
277
+ }
278
+
213
279
  results[compName] = data;
214
280
  } catch (error) {
215
- // If latest mode and today fails, try yesterday
216
- if (mode === 'latest') {
281
+ // If latest mode and today fails, try yesterday (for non-RecommendedPopularInvestors)
282
+ if (mode === 'latest' && compName !== 'RecommendedPopularInvestors') {
217
283
  try {
218
284
  const yesterday = new Date();
219
285
  yesterday.setDate(yesterday.getDate() - 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.671",
3
+ "version": "1.0.673",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [