bulltrackers-module 1.0.520 → 1.0.521
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.
|
@@ -10,7 +10,7 @@ const { getEffectiveCid, getDevOverride } = require('../dev/dev_helpers');
|
|
|
10
10
|
/**
|
|
11
11
|
* Check if a PI exists in a computation date
|
|
12
12
|
* Returns { found: boolean, profileData: object | null, computationData: object | null }
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {object} db - Firestore instance
|
|
14
14
|
* @param {string} insightsCollection - Insights collection name
|
|
15
15
|
* @param {string} resultsSub - Results subcollection name
|
|
16
16
|
* @param {string} compsSub - Computations subcollection name
|
|
@@ -97,6 +97,26 @@ async function checkPiInComputationDate(db, insightsCollection, resultsSub, comp
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Helper: Get computation metadata from schema collection
|
|
102
|
+
* @param {object} db - Firestore instance
|
|
103
|
+
* @param {string} computationName - Computation name
|
|
104
|
+
* @param {object} config - Config object
|
|
105
|
+
* @returns {Promise<object|null>} Metadata object or null if not found
|
|
106
|
+
*/
|
|
107
|
+
async function getComputationMetadata(db, computationName, config) {
|
|
108
|
+
try {
|
|
109
|
+
const schemaCollection = config.schemaCollection || 'computation_schemas';
|
|
110
|
+
const schemaDoc = await db.collection(schemaCollection).doc(computationName).get();
|
|
111
|
+
if (schemaDoc.exists) {
|
|
112
|
+
return schemaDoc.data().metadata || null;
|
|
113
|
+
}
|
|
114
|
+
} catch (err) {
|
|
115
|
+
// Non-critical, return null
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
100
120
|
/**
|
|
101
121
|
* GET /user/me/computations
|
|
102
122
|
* Fetches computation results for a specific signed-in user
|
|
@@ -128,6 +148,15 @@ async function getUserComputations(req, res, dependencies, config) {
|
|
|
128
148
|
return res.status(400).json({ error: "Please specify at least one computation name" });
|
|
129
149
|
}
|
|
130
150
|
|
|
151
|
+
// [NEW] Pre-fetch metadata for all computations to determine which are meta vs standard
|
|
152
|
+
const computationMetadata = {};
|
|
153
|
+
for (const compName of computationNames) {
|
|
154
|
+
const metadata = await getComputationMetadata(db, compName, config);
|
|
155
|
+
if (metadata) {
|
|
156
|
+
computationMetadata[compName] = metadata;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
131
160
|
const isDevOverrideActive = devOverride && devOverride.enabled && devOverride.fakeCopiedPIs.length > 0;
|
|
132
161
|
|
|
133
162
|
let datesToCheck = [today];
|
|
@@ -219,7 +248,22 @@ async function getUserComputations(req, res, dependencies, config) {
|
|
|
219
248
|
}
|
|
220
249
|
}
|
|
221
250
|
|
|
222
|
-
|
|
251
|
+
// [FIX] Handle meta computations (global results) vs standard computations (user-specific)
|
|
252
|
+
// Use metadata from schema collection to determine computation type
|
|
253
|
+
let userResult = null;
|
|
254
|
+
if (data && typeof data === 'object') {
|
|
255
|
+
const metadata = computationMetadata[compName];
|
|
256
|
+
const isMetaComputation = metadata && metadata.type === 'meta';
|
|
257
|
+
|
|
258
|
+
if (isMetaComputation) {
|
|
259
|
+
// Meta computation: return entire data object (global results)
|
|
260
|
+
userResult = data;
|
|
261
|
+
} else {
|
|
262
|
+
// Standard computation: extract user-specific result
|
|
263
|
+
const userCidKey = String(effectiveCid);
|
|
264
|
+
userResult = data.hasOwnProperty(userCidKey) ? data[userCidKey] : null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
223
267
|
|
|
224
268
|
if (isDevOverrideActive && (compName === 'SignedInUserProfileMetrics' || compName === 'SignedInUserCopiedPIs')) {
|
|
225
269
|
if (compName === 'SignedInUserCopiedPIs') {
|