File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ export class BenchmarkController {
42
42
@ApiOkResponse ( { type : Benchmark , description : 'Requested benchmark' } )
43
43
@Get ( ':id' )
44
44
async getBenchmarkById (
45
- @Param ( ) id : BenchmarkIdDto ,
45
+ @Param ( ) benchmarkIdDto : BenchmarkIdDto ,
46
46
) : Promise < Benchmark | undefined > {
47
- return this . benchmarkService . findOne ( id ) ;
47
+ return this . benchmarkService . findOne ( benchmarkIdDto . id ) ;
48
48
}
49
49
}
Original file line number Diff line number Diff line change 1
- import { Injectable } from '@nestjs/common' ;
1
+ import { BadRequestException , Injectable } from '@nestjs/common' ;
2
2
import { Repository } from 'typeorm' ;
3
3
import { InjectRepository } from '@nestjs/typeorm' ;
4
+ import { isUUID } from 'class-validator' ;
4
5
import { CreateBenchmarkDto } from './dto/create-benchmark.dto' ;
5
6
import { Benchmark } from './benchmark.entity' ;
6
7
import { User } from '../users/user.entity' ;
@@ -25,7 +26,16 @@ export class BenchmarkService {
25
26
return this . benchmarkRepository . find ( { } ) ;
26
27
}
27
28
28
- async findOne ( id : { id : string } ) : Promise < Benchmark | undefined > {
29
- return this . benchmarkRepository . findOne ( id ) ;
29
+ async findOne ( id : string ) : Promise < Benchmark | undefined > {
30
+ if ( ! isUUID ( id ) ) {
31
+ throw new BadRequestException ( `Invalid benchmark id: ${ id } ` ) ;
32
+ }
33
+ const benchmark = await this . benchmarkRepository . findOne ( id ) ;
34
+
35
+ if ( ! benchmark ) {
36
+ throw new BadRequestException ( `Could not find benchmark: ${ id } ` ) ;
37
+ }
38
+
39
+ return benchmark ;
30
40
}
31
41
}
You can’t perform that action at this time.
0 commit comments