update forgetPassword route url

This commit is contained in:
秦秋旭 2023-02-24 00:28:58 +08:00
parent 03ad1187ce
commit 56ae208717
3 changed files with 8 additions and 8 deletions

View File

@ -5,4 +5,7 @@ export class ResetPassword extends EmailVerifyDto {
@IsNotEmpty()
@IsStrongPassword()
password: string
@IsNotEmpty()
userId: string
}

View File

@ -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)
}
}

View File

@ -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 })