Skip to content

Commit

Permalink
Refactor: Move user module local guard from handler level to controll…
Browse files Browse the repository at this point in the history
…er scope. Apply @AllowPublic to credential API
  • Loading branch information
J-Hoplin committed Jan 22, 2024
1 parent 7ab7378 commit 1ea68a6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CheckCredentialDto, UpdatePasswordDto } from './dto';
import { UpdateUserInfoDto } from './dto/update-user-info.dto';
import { UserDocs } from './user.docs';
import { UserService } from './user.service';
import { GetUser } from 'app/decorator';
import { AllowPublic, GetUser } from 'app/decorator';
import { Role } from 'app/decorator/role.decorator';
import { RoleGuard } from 'app/guard';
import { SetContributerDto } from './dto/set-contributor';
Expand All @@ -28,26 +28,26 @@ import {
} from 'app/config';

@Controller('user')
@UseGuards(LocalGuard)
@UserDocs.Controller()
export class UserController {
constructor(private userService: UserService) {}

@Get('profile')
@UseGuards(LocalGuard)
@UserDocs.GetMyProfile()
getMyProfile(@GetUser() user: UserDomain) {
return this.userService.getMyProfile(user);
}

@Get('profile/:uid')
@UseGuards(LocalGuard)
@UserDocs.GetProfile()
getProfile(@Param('uid') uid: string) {
return this.userService.getProfile(uid);
}

@Post('credential')
@HttpCode(200)
@AllowPublic()
@UserDocs.CheckCredential()
checkCredential(@Body() dto: CheckCredentialDto) {
return this.userService.checkCredential(dto);
Expand All @@ -60,7 +60,6 @@ export class UserController {
FileOptionFactory(UserProfileImageArtifactConfig),
),
)
@UseGuards(LocalGuard)
@UserDocs.updateUserInfo()
updateUserInfo(
@GetUser() user: UserDomain,
Expand All @@ -71,7 +70,6 @@ export class UserController {
}

@Patch('password')
@UseGuards(LocalGuard)
@UserDocs.updatePassword()
updatePassword(@GetUser() user: UserDomain, @Body() dto: UpdatePasswordDto) {
return this.userService.updatePassword(user, dto);
Expand All @@ -80,7 +78,6 @@ export class UserController {
@Patch(['admin/role', 'role'])
@Role(['Admin'])
@UseGuards(RoleGuard)
@UseGuards(LocalGuard)
@UserDocs.setRole()
setRole(@GetUser() user: UserDomain, @Body() dto: SetContributerDto) {
return this.userService.setRole(user, dto);
Expand Down

0 comments on commit 1ea68a6

Please sign in to comment.