Skip to content

Commit 3ad4e0d

Browse files
committed
feat: add full ranking overview for past results
1 parent 21e116e commit 3ad4e0d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/routes/results.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ export const setupResultsRoutes = function(app: Express, prisma: PrismaClient):
3030
});
3131
});
3232

33+
app.get('/results/:bloc_deadline_id/coalitions/:coalition_slug', async (req, res) => {
34+
const endedSeasons = await getEndedSeasons(prisma);
35+
const season = endedSeasons.find(season => season.id === parseInt(req.params.bloc_deadline_id, 10));
36+
if (!season) {
37+
return res.status(404).send('Season not found or has not ended yet.');
38+
}
39+
40+
const { seasonResults } = await getSeasonResults(prisma, season.id, RANKING_MAX);
41+
const seasonResult = seasonResults.find(result => result.coalition.intra_coalition.slug === req.params.coalition_slug);
42+
if (!seasonResult) {
43+
return res.status(404).send('Coalition not found for this season.');
44+
}
45+
46+
return res.render('ranking.njk', {
47+
pageranking: seasonResult.scores.map((entry, index) => ({ // Transform to match ranking.njk expected format
48+
rankingName: `${seasonResult.coalition.intra_coalition.name} Leaderboards - Season ${season.id}`,
49+
user: entry.user.intra_user,
50+
coalition: seasonResult.coalition,
51+
score: entry.score,
52+
rank: entry.coalition_rank,
53+
})),
54+
rankingTitle: `${seasonResult.coalition.intra_coalition.name} Leaderboards - Season ${season.id}`,
55+
coalitionColored: false,
56+
});
57+
});
58+
3359
app.get('/results/:bloc_deadline_id/coalitions/:coalition_slug.csv', async (req, res) => {
3460
const endedSeasons = await getEndedSeasons(prisma);
3561
const season = endedSeasons.find(season => season.id === parseInt(req.params.bloc_deadline_id, 10));
@@ -54,6 +80,33 @@ export const setupResultsRoutes = function(app: Express, prisma: PrismaClient):
5480
return res.send(csv);
5581
});
5682

83+
app.get('/results/:bloc_deadline_id/rankings/:ranking_type', async (req, res) => {
84+
const endedSeasons = await getEndedSeasons(prisma);
85+
const season = endedSeasons.find(season => season.id === parseInt(req.params.bloc_deadline_id, 10));
86+
if (!season) {
87+
return res.status(404).send('Season not found or has not ended yet.');
88+
}
89+
90+
const { seasonResults, rankings } = await getSeasonResults(prisma, season.id, RANKING_MAX);
91+
const ranking = rankings.find(r => r.type === req.params.ranking_type);
92+
if (!ranking) {
93+
return res.status(404).send('Ranking not found for this season.');
94+
}
95+
96+
return res.render('ranking.njk', {
97+
pageranking: ranking.results.map((entry, index) => ({ // Transform to match ranking.njk expected format
98+
rankingName: ranking.name,
99+
user: entry.user.intra_user,
100+
coalition: entry.coalition ? entry.coalition.intra_coalition : null,
101+
score: entry.score,
102+
rank: entry.rank,
103+
})),
104+
rankingTitle: `${ranking.name} - Season ${season.id}`,
105+
rankingDescription: ranking.description,
106+
coalitionColored: true,
107+
});
108+
});
109+
57110
app.get('/results/:bloc_deadline_id/rankings/:ranking_type.csv', async (req, res) => {
58111
const endedSeasons = await getEndedSeasons(prisma);
59112
const season = endedSeasons.find(season => season.id === parseInt(req.params.bloc_deadline_id, 10));

templates/results.njk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
{# if no rankings, display a message #}
9494
{% if seasonResult.scores | length == 0 %}
9595
<p class="text-muted p-4"><i>No individual leaderboards available for this coalition.</i></p>
96+
{% else %}
97+
<p class="m-2 text-end"><a href="/results/{{ seasonId }}/coalitions/{{ seasonResult.coalition.intra_coalition.slug }}">View full rankings</a></p>
9698
{% endif %}
9799
</div>
98100
</div>
@@ -132,6 +134,8 @@
132134
{# if no rankings, display a message #}
133135
{% if ranking.results | length == 0 %}
134136
<p class="text-muted p-4"><i>No rankings available for this season.</i></p>
137+
{% else %}
138+
<p class="m-2 text-end"><a href="/results/{{ seasonId }}/{{ ranking.type }}">View full rankings</a></p>
135139
{% endif %}
136140
</div>
137141
</div>

0 commit comments

Comments
 (0)