1- import { Body , Controller , Get , Param , Post , Request , UseGuards } from '@nestjs/common' ;
2- import { CreateBenchmarkDto } from 'src/benchmarks/dto/create-benchmark.dto' ;
3- import { BenchmarkService } from 'src/benchmarks/benchmark.service' ;
4- import { Benchmark } from './benchmark.entity' ;
5- import { JwtAuthGuard } from '../auth/jwt-auth.guard' ;
6- import { ValidatedJWTReq } from '../auth/dto/validated-jwt-req' ;
7- import { ApiOkResponse , ApiOperation } from '@nestjs/swagger' ;
8- import { BenchmarkIdDto } from './dto/benchmarkId.dto' ;
9-
10-
11- @Controller ( 'benchmarks' )
12- export class BenchmarkController {
13- constructor ( private readonly benchmarkService : BenchmarkService ) {
14- }
15-
16- @ApiOperation ( { summary : 'Create a benchmark' } )
17- @ApiOkResponse ( { type : Benchmark , description : 'Created benchmark' } )
18-
19- @Post ( )
20- @UseGuards ( JwtAuthGuard )
21- async createBenchmark (
22- @Request ( ) req : ValidatedJWTReq ,
23- @Body ( )
24- benchmark : CreateBenchmarkDto
25- ) : Promise < Benchmark > {
26- return this . benchmarkService . create ( benchmark , req . user ) ;
27- }
28-
29- @ApiOperation ( { summary : 'Get all benchmarks' } )
30- @ApiOkResponse ( { type : [ Benchmark ] , description : 'Array of benchmarks' } )
31- @Get ( )
32- async getEveryBenchMarks ( ) : Promise < Benchmark [ ] > {
33- return this . benchmarkService . getAll ( ) ;
34- }
35-
36- @ApiOperation ( { summary : 'Get benchmark by id' } )
37- @ApiOkResponse ( { type : Benchmark , description : 'Requested benchmark' } )
38- @Get ( ':id' )
39- async getBenchmarkById ( @Param ( ) id : BenchmarkIdDto ) : Promise < Benchmark | undefined > {
40- return this . benchmarkService . findOne ( id ) ;
41- }
42-
43-
44- }
1+ import {
2+ Body ,
3+ Controller ,
4+ Get ,
5+ Param ,
6+ Post ,
7+ Request ,
8+ UseGuards ,
9+ } from '@nestjs/common' ;
10+ import { ApiOkResponse , ApiOperation } from '@nestjs/swagger' ;
11+ import { BenchmarkService } from 'src/benchmarks/benchmark.service' ;
12+ import { CreateBenchmarkDto } from 'src/benchmarks/dto/create-benchmark.dto' ;
13+ import { ValidatedJWTReq } from '../auth/dto/validated-jwt-req' ;
14+ import { JwtAuthGuard } from '../auth/jwt-auth.guard' ;
15+ import { Benchmark } from './benchmark.entity' ;
16+ import { BenchmarkIdDto } from './dto/benchmarkId.dto' ;
17+
18+ @Controller ( 'benchmarks' )
19+ export class BenchmarkController {
20+ constructor ( private readonly benchmarkService : BenchmarkService ) { }
21+
22+ @ApiOperation ( { summary : 'Create a benchmark' } )
23+ @ApiOkResponse ( { type : Benchmark , description : 'Created benchmark' } )
24+ @Post ( )
25+ @UseGuards ( JwtAuthGuard )
26+ async createBenchmark (
27+ @Request ( ) req : ValidatedJWTReq ,
28+ @Body ( )
29+ benchmark : CreateBenchmarkDto ,
30+ ) : Promise < Benchmark > {
31+ return this . benchmarkService . create ( benchmark , req . user ) ;
32+ }
33+
34+ @ApiOperation ( { summary : 'Get all benchmarks' } )
35+ @ApiOkResponse ( { type : [ Benchmark ] , description : 'Array of benchmarks' } )
36+ @Get ( )
37+ async getEveryBenchMarks ( ) : Promise < Benchmark [ ] > {
38+ return this . benchmarkService . getAll ( ) ;
39+ }
40+
41+ @ApiOperation ( { summary : 'Get benchmark by id' } )
42+ @ApiOkResponse ( { type : Benchmark , description : 'Requested benchmark' } )
43+ @Get ( ':id' )
44+ async getBenchmarkById (
45+ @Param ( ) id : BenchmarkIdDto ,
46+ ) : Promise < Benchmark | undefined > {
47+ return this . benchmarkService . findOne ( id ) ;
48+ }
49+ }
0 commit comments