Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/apis/users/interface/users.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ export interface IUsersServiceUpdatePwd {
userId: string;
updateUserInput: UpdateUserInput;
}

export interface IUsersServiceResetPassword {
email: string;
newPassword: string;
}
13 changes: 11 additions & 2 deletions src/apis/users/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,25 @@ export class UsersResolver {
return this.usersService.update({ userId, updateUserInput });
}

// 비밀번호 찾기(초기화하기)
@Mutation(() => User, { description: 'Return: 비밀번호 초기화하기(찾기)' })
resetPwd(
@Args('email') email: string, //
@Args('newPassword') newPassword: string,
): Promise<User> {
return this.usersService.resetPassword({ email, newPassword });
}

// 이메일 인증번호 전송
@Mutation(() => String, { description: ' 이메일 인증번호 전송 ' })
@Mutation(() => String, { description: ' Return: 이메일 인증번호 전송 ' })
getTokenEmail(
@Args('email') email: string, //
): Promise<string> {
return this.usersService.sendTokenEmail({ email });
}

// 이메일 인증번호 검증
@Mutation(() => Boolean, { description: '인증번호 검증' })
@Mutation(() => Boolean, { description: 'Return: 인증번호 검증' })
checkValidToken(
@Args('email') email: string, //
@Args('token') token: string,
Expand Down
25 changes: 22 additions & 3 deletions src/apis/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IUsersServiceFindOne,
IUsersServiceFindOneByEmail,
IUsersServiceFindUserDog,
IUsersServiceResetPassword,
IUsersServiceSendEmail,
IUsersServiceSendTokenEmail,
IUsersServiceUpdate,
Expand Down Expand Up @@ -173,23 +174,41 @@ export class UsersService {
});
return true;
}

// 회원 수정하기
async update({
userId, //
updateUserInput,
}: IUsersServiceUpdate): Promise<User> {
const user = await this.findOne({ userId });

const hasedPassword = await bcrypt.hash(updateUserInput.password, 10);

if (updateUserInput.password) {
updateUserInput.password = await bcrypt.hash(
updateUserInput.password,
10,
);
}
const result = await this.userRepository.save({
...user,
...updateUserInput,
password: hasedPassword,
});
return result;
}

// 비밀번호 찾기(초기화하기)
async resetPassword({
email,
newPassword,
}: IUsersServiceResetPassword): Promise<User> {
const theUser = await this.userRepository.findOne({
where: { email },
});

theUser.password = await bcrypt.hash(newPassword, 10);

return await this.userRepository.save(theUser);
}

// 유저 삭제하기(삭제는 나중에)
async delete({
userId, //
Expand Down