41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common'
|
|
import { RunsService } from './runs.service'
|
|
import { RunEntity } from './entities/run.entity'
|
|
import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto'
|
|
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
|
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'
|
|
import { ApiBearerAuth } from '@nestjs/swagger'
|
|
import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/pagination.utils'
|
|
|
|
@Controller('runs')
|
|
export class RunsController {
|
|
constructor(private readonly runsService: RunsService) {}
|
|
|
|
/**
|
|
* Recherche de tentatives de course
|
|
*
|
|
* @throws {401} Non authentifié⋅e
|
|
*/
|
|
@Get()
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiOkResponsePaginated(RunEntity)
|
|
async findAll(@Query() queryPagination: QueryPaginationDto): Promise<PaginateOutputDto<RunEntity>> {
|
|
const [runs, total] = await this.runsService.findAll(queryPagination)
|
|
return paginateOutput<RunEntity>(runs.map(challenge => new RunEntity(challenge)), total, queryPagination)
|
|
}
|
|
|
|
/**
|
|
* Recherche d'une tentative de course par identifiant
|
|
*
|
|
* @throws {401} Non authentifié⋅e
|
|
* @throws {404} Essai non trouvé
|
|
*/
|
|
@Get(':id')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
async findOne(@Param('id') id: number): Promise<RunEntity> {
|
|
return new RunEntity(await this.runsService.findOne(id))
|
|
}
|
|
}
|