-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 유저 닉네임 변경 API 추가 #223
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class RenameUserDto { | ||
@ApiProperty({ description: '변경할 닉네임' }) | ||
nickname: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
BadRequestException, | ||
Injectable, | ||
NotFoundException, | ||
} from '@nestjs/common'; | ||
import { UserRepository } from './user.repository'; | ||
import { ProfileResponseDto } from './dto/profile-response.dto'; | ||
|
||
|
@@ -10,4 +14,20 @@ export class UserService { | |
const user = await this.userRepository.findOneBy({ id: userId }); | ||
return new ProfileResponseDto(user.nickname, user.email); | ||
} | ||
|
||
async renameUser(userId: number, newName: string) { | ||
const user = await this.userRepository.findOneBy({ id: userId }); | ||
if (!user) { | ||
throw new NotFoundException('존재하지 않는 유저입니다.'); | ||
} | ||
|
||
const isDuplicated = await this.userRepository.findBy({ | ||
nickname: newName, | ||
}); | ||
if (isDuplicated.length > 0) { | ||
throw new BadRequestException('이미 존재하는 닉네임입니다.'); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 existsBy 이런거로 boolean 값 받아서 할 수도 있을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오우..! 저도 저런 식으로만 했어서 생각도 못했네요 그런 메소드가 있었군요..! 감사합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안그래도 boolean 으로 하고 싶었는데 저렇게 찾으니까 없는 경우에도 빈 배열이어서.. 뭐 어떤 상황에서도 다 true로 가지고 오더라구요..ㅋㅋㅋ |
||
return this.userRepository.update({ id: userId }, { nickname: newName }); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 닉네임 수정은 patch 메소드가 더 낫지 않을까용...? 어떻게 생각하세요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 완전 좋아요 patch!!
맞아요.. 당연한건데.. 전체 수정이 아니라 부분 수정이니까!!
당장 반영하겠습니다.