-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from f-lab-edu/feature/17-get-member-update-de…
…lete [#17] 멤버 정보 가져오기, 수정, 삭제 기능
- Loading branch information
Showing
8 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
ForbiddenException, | ||
Get, | ||
NotFoundException, | ||
Param, | ||
ParseIntPipe, | ||
Patch, | ||
} from "@nestjs/common"; | ||
import * as bcrypt from "bcrypt"; | ||
|
||
import { CurrentMemberDecorator } from "@APP/common/decorators/current-member.decorator"; | ||
import { UpdateMemberDto } from "@APP/dtos/update-member.dto"; | ||
import { MembersService } from "@APP/services/members.service"; | ||
|
||
@Controller("members") | ||
export class MembersController { | ||
constructor(private readonly membersService: MembersService) {} | ||
|
||
@Get(":memberId") | ||
getMember(@Param("memberId", new ParseIntPipe()) memberId: number) { | ||
return this.membersService.findById(memberId); | ||
} | ||
|
||
@Delete(":memberId") | ||
async deleteMember( | ||
@CurrentMemberDecorator("id") currentMemberId: number, | ||
@Param("memberId", new ParseIntPipe()) memberId: number, | ||
) { | ||
const member = await this.membersService.findById(memberId); | ||
|
||
if (!member) { | ||
throw new NotFoundException("존재하지 않는 회원입니다."); | ||
} | ||
|
||
if (currentMemberId !== memberId) { | ||
throw new ForbiddenException("권한이 없습니다."); | ||
} | ||
|
||
await this.membersService.deleteById(memberId); | ||
} | ||
|
||
@Patch(":memberId") | ||
async patchMember( | ||
@CurrentMemberDecorator("id") currentMemberId: number, | ||
@Param("memberId", new ParseIntPipe()) memberId: number, | ||
@Body() dto: UpdateMemberDto, | ||
) { | ||
const member = await this.membersService.findById(memberId); | ||
|
||
if (!member) { | ||
throw new NotFoundException("존재하지 않는 회원입니다."); | ||
} | ||
|
||
if (currentMemberId !== memberId) { | ||
throw new ForbiddenException("권한이 없습니다."); | ||
} | ||
|
||
if (dto.password) { | ||
const hashedPassword = await bcrypt.hash(dto.password, 10); | ||
dto.password = hashedPassword; | ||
} | ||
|
||
await this.membersService.updateById(memberId, dto); | ||
|
||
return this.membersService.findById(memberId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { OmitType, PartialType } from "@nestjs/swagger"; | ||
|
||
import { RegisterMemberDto } from "./register-member.dto"; | ||
|
||
export class UpdateMemberDto extends PartialType( | ||
OmitType(RegisterMemberDto, ["email"]), | ||
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters