Skip to content

Commit 4969418

Browse files
committed
fix: include disco piscine name in page subtitle
1 parent e3805f0 commit 4969418

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/routes/disco.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Express } from 'express';
22
import passport from 'passport';
33
import { PrismaClient } from '@prisma/client';
4-
import { formatDate, getAllDiscoPiscines, getLatestDiscoPiscine, hasLimitedPiscineHistoryAccess, projectStatusToString } from '../utils';
4+
import { formatDate, getAllDiscoPiscines, getLatestDiscoPiscine, hasLimitedPiscineHistoryAccess, projectStatusToString, shortenDiscoPiscineCursusName } from '../utils';
55
import { checkIfStudentOrStaff, checkIfCatOrStaff, checkIfPiscineHistoryAccess } from '../handlers/middleware';
66
import { getDiscoPiscineData } from '../handlers/disco';
77
import { IntraUser } from '../intra/oauth';
@@ -43,6 +43,14 @@ export const setupDiscoPiscineRoutes = function(app: Express, prisma: PrismaClie
4343
// Find all possible disco piscines from the database (if not staff, limit to the current year)
4444
const discopiscines = await getAllDiscoPiscines(prisma, hasLimitedPiscineHistoryAccess(req.user as IntraUser));
4545

46+
// Get the discovery piscine based on the year and week
47+
const discopiscine = discopiscines.find(p => p.year_num === year && p.week_num === week && p.cursus.id === cursus_id);
48+
if (!discopiscine) {
49+
console.log(`No discovery piscine found for year ${year}, week ${week} and cursus_id ${cursus_id}`);
50+
res.status(404);
51+
return;
52+
}
53+
4654
const piscineData = await getDiscoPiscineData(prisma, year, week, cursus_id);
4755
if (!piscineData) {
4856
console.log(`No discovery piscine found for year ${year}, week ${week} and cursus_id ${cursus_id}`);
@@ -51,7 +59,7 @@ export const setupDiscoPiscineRoutes = function(app: Express, prisma: PrismaClie
5159
}
5260

5361
const { users, logtimes, dropouts, activeStudents, projects } = piscineData;
54-
return res.render('disco.njk', { discopiscines, projects, users, logtimes, dropouts, activeStudents, year, week, cursus_id, subtitle: `${year} Week ${week}` });
62+
return res.render('disco.njk', { discopiscines, projects, users, logtimes, dropouts, activeStudents, year, week, cursus_id, subtitle: `${year} week ${week}: ${shortenDiscoPiscineCursusName(discopiscine.cursus.name)})` });
5563
});
5664

5765
app.get('/disco/:year/:week/:cursus_id/csv', passport.authenticate('session'), checkIfStudentOrStaff, checkIfCatOrStaff, checkIfPiscineHistoryAccess, async (req, res) => {

0 commit comments

Comments
 (0)