@@ -15,14 +15,19 @@ import {
15
15
ApiParam ,
16
16
} from '@nestjs/swagger' ;
17
17
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard' ;
18
+ import { Benchmark } from 'src/benchmarks/benchmark.entity' ;
19
+ import { BenchmarkService } from 'src/benchmarks/benchmark.service' ;
18
20
import { CreateUserDTO } from './dto/create-user.dto' ;
19
21
import { FindUserDTO } from './dto/find-user.dto' ;
20
22
import { User } from './user.entity' ;
21
23
import { UsersService } from './users.service' ;
22
24
23
25
@Controller ( 'users' )
24
26
export class UsersController {
25
- constructor ( private readonly usersService : UsersService ) { }
27
+ constructor (
28
+ private readonly usersService : UsersService ,
29
+ private readonly benchmarkService : BenchmarkService ,
30
+ ) { }
26
31
27
32
@Post ( )
28
33
async signupUser (
@@ -59,4 +64,18 @@ export class UsersController {
59
64
60
65
return user ;
61
66
}
67
+
68
+ @ApiOperation ( { summary : 'Get benchmarks for user' } )
69
+ @ApiOkResponse ( { type : [ Benchmark ] , description : 'Array of benchmarks' } )
70
+ @Get ( ':username/benchmarks' )
71
+ async getBenchmarkForUser (
72
+ @Param ( ) userReq : { username : string } ,
73
+ ) : Promise < Benchmark [ ] > {
74
+ const user = await this . usersService . findOne ( userReq ) ;
75
+ if ( ! user ) {
76
+ throw new NotFoundException ( 'User not found' ) ;
77
+ }
78
+
79
+ return this . benchmarkService . findBy ( { where : { creator : user } } ) ;
80
+ }
62
81
}
0 commit comments