1- import { Body , Controller , Get , Post , Query } from '@nestjs/common' ;
1+ import {
2+ BadRequestException ,
3+ Body ,
4+ Controller ,
5+ Get ,
6+ Post ,
7+ Query ,
8+ } from '@nestjs/common' ;
29import { UserService } from './user.service' ;
310import {
411 EditVoteDto ,
@@ -21,30 +28,60 @@ export class UserController {
2128 async getUserData (
2229 @Query ( ) query : GetUserDataDto ,
2330 ) : Promise < UserDataResponseDto > {
24- return this . userService . getUserData ( query ) ;
31+ try {
32+ return this . userService . getUserData ( query ) ;
33+ } catch ( error : unknown ) {
34+ const errorMessage =
35+ error instanceof Error ? error . message : 'An unexpected error occurred' ;
36+ throw new BadRequestException ( errorMessage ) ;
37+ }
2538 }
2639
2740 @Get ( 'getUserActivities' )
2841 async getUserActivities (
2942 @Query ( ) query : GetUserActivitiesDto ,
3043 ) : Promise < UserActivitiesResponseDto > {
31- return this . userService . getUserActivities ( query ) ;
44+ try {
45+ return this . userService . getUserActivities ( query ) ;
46+ } catch ( error : unknown ) {
47+ const errorMessage =
48+ error instanceof Error ? error . message : 'An unexpected error occurred' ;
49+ throw new BadRequestException ( errorMessage ) ;
50+ }
3251 }
3352
3453 @Post ( 'getUserVotes' )
3554 async getUserVotes (
3655 @Body ( ) body : GetUserVotesDto ,
3756 ) : Promise < UserVotesResponseDto > {
38- return this . userService . getUserVotes ( body ) ;
57+ try {
58+ return await this . userService . getUserVotes ( body ) ;
59+ } catch ( error : unknown ) {
60+ const errorMessage =
61+ error instanceof Error ? error . message : 'An unexpected error occurred' ;
62+ throw new BadRequestException ( errorMessage ) ;
63+ }
3964 }
4065
4166 @Post ( 'setVote' )
4267 async setVote ( @Body ( ) dto : SetVoteDto ) : Promise < SetVoteResponseDto > {
43- return this . userService . setVote ( dto ) ;
68+ try {
69+ return this . userService . setVote ( dto ) ;
70+ } catch ( error : unknown ) {
71+ const errorMessage =
72+ error instanceof Error ? error . message : 'An unexpected error occurred' ;
73+ throw new BadRequestException ( errorMessage ) ;
74+ }
4475 }
4576
4677 @Post ( 'editVote' )
4778 async editVote ( @Body ( ) dto : EditVoteDto ) : Promise < EditVoteResponseDto > {
48- return this . userService . editVote ( dto ) ;
79+ try {
80+ return this . userService . editVote ( dto ) ;
81+ } catch ( error : unknown ) {
82+ const errorMessage =
83+ error instanceof Error ? error . message : 'An unexpected error occurred' ;
84+ throw new BadRequestException ( errorMessage ) ;
85+ }
4986 }
5087}
0 commit comments