From 56ae208717455f541bbe66c4e60307a8b8c571d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E7=A7=8B=E6=97=AD?= Date: Fri, 24 Feb 2023 00:28:58 +0800 Subject: [PATCH] update forgetPassword route url --- src/users/dto/reset-password.dto.ts | 3 +++ src/users/users.controller.ts | 9 +++------ src/users/users.service.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/users/dto/reset-password.dto.ts b/src/users/dto/reset-password.dto.ts index e35ffc1..ec976a3 100644 --- a/src/users/dto/reset-password.dto.ts +++ b/src/users/dto/reset-password.dto.ts @@ -5,4 +5,7 @@ export class ResetPassword extends EmailVerifyDto { @IsNotEmpty() @IsStrongPassword() password: string + + @IsNotEmpty() + userId: string } diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 527a6b9..37bdaac 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -23,12 +23,9 @@ export class UsersController { return this.usersService.loginByEmail(user.email, user.password) } - @Patch(':id/password') + @Patch('password') @ApiOperation({ summary: '找回密码' }) - async forgetPassword( - @Body() payload: ResetPassword, - @Param('id') userId: string, - ) { - return this.usersService.resetPasswordByEmail(payload, userId) + async forgetPassword(@Body() payload: ResetPassword) { + return this.usersService.resetPasswordByEmail(payload) } } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 88b3694..b463fa7 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -47,14 +47,14 @@ export class UsersService { } @VerifyEmail(EmailScene.forgetPassword) - async resetPasswordByEmail(data: ResetPassword, userId: string) { + async resetPasswordByEmail(data: ResetPassword) { const { password } = data const hashedPassword = await bcrypt.hash( password, this.secureConfig.bcryptSaltOrRound, ) const user = await this.prismaService.user.update({ - where: { id: userId }, + where: { id: data.userId }, data: { password: hashedPassword }, }) return this.generateTokens({ userId: user.id })