Skip to content

Commit 25dc3d1

Browse files
committed
Add endpoint to retrieve FrameStep plot data with optional query filtering
1 parent 03eaaff commit 25dc3d1

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎src/routes/projects/summary/index.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,47 @@ router.route('/growth').get(
7272
}),
7373
);
7474

75+
// Endpoint to get only the fields required by the FrameStep plot
76+
router.route('/framestep').get(
77+
handler({
78+
async retriever(request) {
79+
// Establish database connection and retrieve our custom handler
80+
const database = await getDatabase(request);
81+
// Start filtering by published projects only if we are in production environment
82+
const finder = database.getBaseFilter();
83+
// Handle optional query filter
84+
const query = request.query.query;
85+
if (query) {
86+
// Process the mongo query to convert references and topology queries
87+
const processedQuery = await database.processProjectsQuery(query);
88+
if (processedQuery.error) return processedQuery;
89+
if (!finder.$and) finder.$and = processedQuery;
90+
else finder.$and = finder.$and.concat(processedQuery);
91+
}
92+
93+
// Keep only projects that can contribute to the FrameStep scatter plot
94+
if (!finder.$and) finder.$and = [];
95+
finder.$and.push({ 'metadata.FRAMESTEP': { $gt: 0 } });
96+
finder.$and.push({ mds: { $exists: true, $ne: [] } });
97+
98+
// Get only the minimum data required by mdposit_client data-summary/framestep
99+
const cursor = await database.projects.find(
100+
finder,
101+
{
102+
projection: {
103+
_id: 0,
104+
'metadata.FRAMESTEP': 1,
105+
'mds.frames': 1,
106+
},
107+
},
108+
);
109+
110+
// Consume the cursor and return data as-is (same shape expected by the plot)
111+
return cursor.toArray();
112+
}
113+
}),
114+
);
115+
75116
// This endpoint returns some summary of data contained in the projects collection
76117
router.route('/').get(
77118
handler({

0 commit comments

Comments
 (0)