Files
HIPCTF2/backend/src/modules/challenges/scoreboard.controller.ts
T

48 lines
1.5 KiB
TypeScript

import { Controller, Get, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { DataSource } from 'typeorm';
import { ZodValidationPipe } from '../../common/pipes/zod-validation.pipe';
import { ScoreboardService } from './scoreboard.service';
import {
EventLogQuerySchema,
EventLogRowDto,
GraphViewDto,
MatrixViewDto,
RankingRowDto,
} from './dto/scoreboard.dto';
@ApiTags('scoreboard')
@ApiBearerAuth()
@Controller('api/v1/scoreboard')
export class ScoreboardController {
constructor(
private readonly dataSource: DataSource,
private readonly svc: ScoreboardService,
) {}
@Get('ranking')
@ApiOperation({ summary: 'Authenticated scoreboard ranking (competition ranks)' })
async ranking(): Promise<RankingRowDto[]> {
return this.svc.getRanking(this.dataSource.manager);
}
@Get('matrix')
@ApiOperation({ summary: 'Authenticated scoreboard matrix (players x challenges)' })
async matrix(): Promise<MatrixViewDto> {
return this.svc.getMatrix(this.dataSource.manager);
}
@Get('event-log')
@ApiOperation({ summary: 'Authenticated recent-solves event log' })
async eventLog(
@Query(new ZodValidationPipe(EventLogQuerySchema)) q: { limit?: number },
): Promise<EventLogRowDto[]> {
return this.svc.getEventLog(this.dataSource.manager, q.limit ?? 50);
}
@Get('graph')
@ApiOperation({ summary: 'Authenticated score graph (top 10 players)' })
async graph(): Promise<GraphViewDto> {
return this.svc.getGraph(this.dataSource.manager);
}
}