11import { Express } from 'express' ;
22import passport from 'passport' ;
33import { PrismaClient } from '@prisma/client' ;
4- import { formatDate , getAllDiscoPiscines , getLatestDiscoPiscine , hasLimitedPiscineHistoryAccess , projectStatusToString } from '../utils' ;
4+ import { formatDate , getAllDiscoPiscines , getLatestDiscoPiscine , hasLimitedPiscineHistoryAccess , projectStatusToString , shortenDiscoPiscineCursusName } from '../utils' ;
55import { checkIfStudentOrStaff , checkIfCatOrStaff , checkIfPiscineHistoryAccess } from '../handlers/middleware' ;
66import { getDiscoPiscineData } from '../handlers/disco' ;
77import { 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