Skip to content

Commit bac2b98

Browse files
committed
fix: use season name instead of season id in past results rankings
1 parent 24c5ea8 commit bac2b98

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/handlers/filters.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Express } from 'express';
22
import nunjucks from 'nunjucks';
3-
import { formatThousands, timeAgo, timeFromNow } from '../utils';
3+
import { formatThousands, getSeasonName, timeAgo, timeFromNow } from '../utils';
44

55
export const setupNunjucksFilters = function(app: Express): void {
66
const nunjucksEnv = nunjucks.configure('templates', {
@@ -122,8 +122,7 @@ export const setupNunjucksFilters = function(app: Express): void {
122122
if (!season || !season.begin_at || !season.end_at) {
123123
return 'Unknown season';
124124
}
125-
// return `${season.begin_at.getFullYear()}-${season.begin_at.getMonth() + 1} > ${season.end_at.getFullYear()}-${season.end_at.getMonth() + 1}`;
126-
return `${season.end_at.toLocaleString('en-US', { month: 'short' })} ${season.end_at.getFullYear()}`;
125+
return getSeasonName(season);
127126
});
128127

129128
// Add filter to remove the first item from a list

src/routes/results.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PrismaClient } from '@prisma/client';
22
import { Express } from 'express';
3-
import { getEndedSeasons, getSeasonResults, RANKING_MAX } from '../utils';
3+
import { getEndedSeasons, getSeasonName, getSeasonResults, RANKING_MAX } from '../utils';
44

55
export const setupResultsRoutes = function(app: Express, prisma: PrismaClient): void {
66
app.get('/results', async (req, res) => {
@@ -45,13 +45,13 @@ export const setupResultsRoutes = function(app: Express, prisma: PrismaClient):
4545

4646
return res.render('ranking.njk', {
4747
pageranking: seasonResult.scores.map((entry, index) => ({ // Transform to match ranking.njk expected format
48-
rankingName: `${seasonResult.coalition.intra_coalition.name} Leaderboards - Season ${season.id}`,
48+
rankingName: `${seasonResult.coalition.intra_coalition.name} Leaderboards - Season ${getSeasonName(season)}`,
4949
user: entry.user.intra_user,
5050
coalition: seasonResult.coalition,
5151
score: entry.score,
5252
rank: entry.coalition_rank,
5353
})),
54-
rankingTitle: `${seasonResult.coalition.intra_coalition.name} Leaderboards - Season ${season.id}`,
54+
rankingTitle: `${seasonResult.coalition.intra_coalition.name} Leaderboards - Season ${getSeasonName(season)}`,
5555
coalitionColored: false,
5656
});
5757
});
@@ -101,7 +101,7 @@ export const setupResultsRoutes = function(app: Express, prisma: PrismaClient):
101101
score: entry.score,
102102
rank: entry.rank,
103103
})),
104-
rankingTitle: `${ranking.name} - Season ${season.id}`,
104+
rankingTitle: `${ranking.name} - Season ${getSeasonName(season)}`,
105105
rankingDescription: ranking.description,
106106
coalitionColored: true,
107107
});

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ export const getEndedSeasons = async function(prisma: PrismaClient): Promise<(In
765765
return seasons;
766766
};
767767

768+
export const getSeasonName = function(bloc: IntraBlocDeadline): string {
769+
// return `${bloc.begin_at.getFullYear()}-${bloc.begin_at.getMonth() + 1} > ${bloc.end_at.getFullYear()}-${bloc.end_at.getMonth() + 1}`;
770+
return `${bloc.end_at.toLocaleString('en-US', { month: 'short' })} ${bloc.end_at.getFullYear()}`;
771+
};
772+
768773
export const getSeasonResults = async function(prisma: PrismaClient, blocDeadlineId: number, topAmount: number = RANKING_MAX) { // Implicit return type
769774
const bloc = await prisma.intraBlocDeadline.findUnique({
770775
where: {

0 commit comments

Comments
 (0)