Skip to content

Commit 9d9dccb

Browse files
committed
feat: add admin-side apisearcher filter for project_id
1 parent 09bb647 commit 9d9dccb

3 files changed

Lines changed: 56 additions & 4 deletions

File tree

src/routes/admin/apisearcher.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export const setupAPISearchRoutes = function(app: Express, prisma: PrismaClient)
209209
});
210210

211211
// Projects (actually teams) by team ID
212-
app.get('/admin/apisearch/projects/id/:teamId', async (req, res) => {
212+
app.get('/admin/apisearch/projects/team_id/:teamId', async (req, res) => {
213213
try {
214214
const teamId = req.params.teamId;
215215
const itemsPerPage = 50;
@@ -233,6 +233,31 @@ export const setupAPISearchRoutes = function(app: Express, prisma: PrismaClient)
233233
}
234234
});
235235

236+
// Projects (actually teams) by project ID
237+
app.get('/admin/apisearch/projects/project_id/:projectId', async (req, res) => {
238+
try {
239+
const projectId = req.params.projectId;
240+
const itemsPerPage = 50;
241+
const pageNum = getPageNumber(req, NaN);
242+
const api = await getAPIClient();
243+
const teams = await fetchSingleApiPage(api, '/teams/', {
244+
'filter[project_id]': projectId,
245+
'page[size]': itemsPerPage.toString(),
246+
}, pageNum);
247+
const modifiedTeams = await parseTeamInAPISearcher(prisma, teams.data);
248+
return res.json({
249+
data: modifiedTeams,
250+
meta: {
251+
pagination: getPaginationMeta(teams.headers),
252+
},
253+
});
254+
}
255+
catch (err) {
256+
console.log(err);
257+
return res.status(500).json({ error: err });
258+
}
259+
});
260+
236261
// EXAMS (ACTUALLY TEAMS TOO)
237262
// All exams (teams)
238263
app.get('/admin/apisearch/exams', async (req, res) => {
@@ -295,7 +320,7 @@ export const setupAPISearchRoutes = function(app: Express, prisma: PrismaClient)
295320
});
296321

297322
// Exams (actually teams) by team ID
298-
app.get('/admin/apisearch/exams/id/:teamId', async (req, res) => {
323+
app.get('/admin/apisearch/exams/team_id/:teamId', async (req, res) => {
299324
try {
300325
const teamId = req.params.teamId;
301326
const itemsPerPage = 50;
@@ -320,6 +345,31 @@ export const setupAPISearchRoutes = function(app: Express, prisma: PrismaClient)
320345
}
321346
});
322347

348+
// Exams (actually teams) by project ID
349+
app.get('/admin/apisearch/exams/project_id/:projectId', async (req, res) => {
350+
try {
351+
const projectId = req.params.projectId;
352+
const itemsPerPage = 50;
353+
const pageNum = getPageNumber(req, NaN);
354+
const api = await getAPIClient();
355+
const teams = await fetchSingleApiPage(api, '/teams/', {
356+
'filter[project_id]': projectId,
357+
'page[size]': itemsPerPage.toString(),
358+
}, pageNum);
359+
const modifiedTeams = await parseTeamInAPISearcher(prisma, teams.data);
360+
return res.json({
361+
data: modifiedTeams,
362+
meta: {
363+
pagination: getPaginationMeta(teams.headers),
364+
},
365+
});
366+
}
367+
catch (err) {
368+
console.log(err);
369+
return res.status(500).json({ error: err });
370+
}
371+
});
372+
323373
// EVALUATIONS (SCALE_TEAMS)
324374
// All evaluations
325375
app.get('/admin/apisearch/evaluations', async (req, res) => {

templates/admin/points/manual/exam.njk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<option value="" selected disabled hidden>Choose a filter</option>
1717
<option value="none">No filter</option>
1818
<option value="login">Login</option>
19-
<option value="id">Team ID</option>
19+
<option value="team_id">Team ID</option>
20+
<option value="project_id">Project ID</option>
2021
</select>
2122
</div>
2223
<div class="col">

templates/admin/points/manual/project.njk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<option value="" selected disabled hidden>Choose a filter</option>
1717
<option value="none">No filter</option>
1818
<option value="login">Login</option>
19-
<option value="id">Team ID</option>
19+
<option value="team_id">Team ID</option>
20+
<option value="project_id">Project ID</option>
2021
</select>
2122
</div>
2223
<div class="col">

0 commit comments

Comments
 (0)