@@ -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 ) ) ;
0 commit comments