From 2e3f15b432786759349840dae3c357e7fb30a514 Mon Sep 17 00:00:00 2001 From: erickimme Date: Thu, 26 Oct 2023 18:19:04 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=99=84=EB=A3=8C]=20=EB=8F=99=EC=9D=BC?= =?UTF-8?q?=ED=95=9C=20=ED=8C=A8=EC=8A=A4=EC=9B=8C=EB=93=9C=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=8B=9C=20=EC=97=90=EB=9F=AC=20=EB=B0=9C=EC=83=9D?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/users/users.controller.ts | 6 +++++- src/users/users.service.ts | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index d2ab046..fea62ce 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -134,13 +134,17 @@ export class UsersController { @ApiOperation({ summary: '비밀번호 변경' }) @ApiResponse({ status: 200, description: '비밀번호가 변경되었습니다' }) @ApiResponse({ status: 404, description: '유저 정보가 존재하지 않습니다' }) + @ApiResponse({ + status: 400, + description: '동일한 비밀번호를 입력하였습니다', + }) @UseGuards(JwtAccessAuthGuard) @ApiBearerAuth() async updatePassword( @Req() req: RequestWithUser, @Body() updateUserPasswordDto: UpdateUserPasswordDto ) { - const { userId } = req.user; // request에 user 객체가 추가되었고 userId에 값 할당 + const { userId } = req.user; await this.usersService.updatePassword(userId, updateUserPasswordDto); return { message: '비밀번호가 변경되었습니다' }; } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 3a7d88a..1794fb0 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -193,7 +193,13 @@ export class UsersService { where: { userId }, }); if (!user) { - throw new BadRequestException('유저 정보가 존재하지 않습니다.'); + throw new BadRequestException('유저 정보가 존재하지 않습니다'); + } + + // 기존 현재 패스워드와 변경하려는 새로운 패스워드가 같은지 확인 후 같은 경우 에러 + const isPasswordMatching = await bcrypt.compare(newPassword, user.password); + if (isPasswordMatching) { + throw new BadRequestException('동일한 비밀번호를 입력하였습니다'); } // password 업데이트