1- import { Controller , Get } from "@nestjs/common" ;
2- import { ApiOperation , ApiTags } from "@nestjs/swagger" ;
1+ import { Controller , Get , Query , Res , UseGuards } from "@nestjs/common" ;
2+ import { ApiBearerAuth , ApiOperation , ApiTags } from "@nestjs/swagger" ;
3+ import { Response } from "express" ;
34import { TopcoderReportsService } from "./topcoder-reports.service" ;
5+ import { RegistrantCountriesQueryDto } from "./dto/registrant-countries.dto" ;
6+ import { TopcoderReportsGuard } from "../../auth/guards/topcoder-reports.guard" ;
47
58@ApiTags ( "Topcoder Reports" )
9+ @ApiBearerAuth ( )
10+ @UseGuards ( TopcoderReportsGuard )
611@Controller ( "/topcoder" )
712export class TopcoderReportsController {
813 constructor ( private readonly reports : TopcoderReportsService ) { }
@@ -13,6 +18,25 @@ export class TopcoderReportsController {
1318 return this . reports . getMemberCount ( ) ;
1419 }
1520
21+ @Get ( "/registrant-countries" )
22+ @ApiOperation ( {
23+ summary : "Countries of all registrants for the specified challenge" ,
24+ } )
25+ async getRegistrantCountries (
26+ @Query ( ) query : RegistrantCountriesQueryDto ,
27+ @Res ( ) res : Response ,
28+ ) {
29+ const { challengeId } = query ;
30+ const csv = await this . reports . getRegistrantCountriesCsv ( challengeId ) ;
31+ const filename =
32+ challengeId . length > 0
33+ ? `registrant-countries-${ challengeId } .csv`
34+ : "registrant-countries.csv" ;
35+ res . setHeader ( "Content-Type" , "text/csv" ) ;
36+ res . setHeader ( "Content-Disposition" , `attachment; filename="${ filename } "` ) ;
37+ res . send ( csv ) ;
38+ }
39+
1640 @Get ( "/total-copilots" )
1741 @ApiOperation ( { summary : "Total number of Copilots" } )
1842 getTotalCopilots ( ) {
0 commit comments