@@ -15,14 +15,19 @@ import {
1515 ApiParam ,
1616} from '@nestjs/swagger' ;
1717import { JwtAuthGuard } from 'src/auth/jwt-auth.guard' ;
18+ import { Benchmark } from 'src/benchmarks/benchmark.entity' ;
19+ import { BenchmarkService } from 'src/benchmarks/benchmark.service' ;
1820import { CreateUserDTO } from './dto/create-user.dto' ;
1921import { FindUserDTO } from './dto/find-user.dto' ;
2022import { User } from './user.entity' ;
2123import { UsersService } from './users.service' ;
2224
2325@Controller ( 'users' )
2426export class UsersController {
25- constructor ( private readonly usersService : UsersService ) { }
27+ constructor (
28+ private readonly usersService : UsersService ,
29+ private readonly benchmarkService : BenchmarkService ,
30+ ) { }
2631
2732 @Post ( )
2833 async signupUser (
@@ -59,4 +64,18 @@ export class UsersController {
5964
6065 return user ;
6166 }
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+ }
6281}
0 commit comments