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
10 changes: 0 additions & 10 deletions src/apis/users/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@ export class UsersResolver {
private readonly usersService: UsersService, //
) {}

// 전체 조회하기
@Query(() => [User], { description: ' Return: 전체 유저 정보 ' })
fetchUsers(): Promise<User[]> {
return this.usersService.findAll();
}

// 하나 조회하기
@Query(() => User, { description: ' Return: 유저 정보 ' })
fetchUser(
@Args('userId') userId: string, //
): Promise<User> {
return this.usersService.findOne({ userId });
}

// 삭제된 유저 조회하기
@Query(() => [User])
fetchUserWithDeleted(): Promise<User[]> {
return this.usersService.findAllWithDeleted();
Expand All @@ -39,7 +36,6 @@ export class UsersResolver {
return this.usersService.duplicationEmail({ email });
}

// 로그인 된 유저 조회하기 (마이페이지가 들어가기 위함)
@UseGuards(GqlAuthGuard('access'))
@Query(() => User, {
description: ' Return : 로그인한 유저, 유저 댕댕이 프로필',
Expand All @@ -50,7 +46,6 @@ export class UsersResolver {
return this.usersService.findUserDog({ email: context.req.user.email });
}

// 회원가입
@Mutation(() => User, { description: ' Return: 유저 회원가입 ' })
createUser(
@Args('name') name: string,
Expand All @@ -66,7 +61,6 @@ export class UsersResolver {
});
}

// 회원 수정하기
@UseGuards(GqlAuthGuard('access'))
@Mutation(() => User, { description: ' Return: 회원정보 업데이트 ' })
updateUser(
Expand All @@ -77,7 +71,6 @@ export class UsersResolver {
return this.usersService.update({ userId, updateUserInput });
}

// 비밀번호 찾기(초기화하기)
@Mutation(() => User, { description: 'Return: 비밀번호 초기화하기(찾기)' })
resetPwd(
@Args('email') email: string, //
Expand All @@ -86,15 +79,13 @@ export class UsersResolver {
return this.usersService.resetPassword({ email, newPassword });
}

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

// 이메일 인증번호 검증
@Mutation(() => Boolean, { description: 'Return: 인증번호 검증' })
checkValidToken(
@Args('email') email: string, //
Expand All @@ -103,7 +94,6 @@ export class UsersResolver {
return this.usersService.checkToken({ email, token });
}

// 유저 삭제하기
@Mutation(() => Boolean, { description: ' Return: 유저 정보 삭제하기 ' })
deleteUser(
@Args('userId') userId: string, //
Expand Down
28 changes: 3 additions & 25 deletions src/apis/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
IUsersServiceSendEmail,
IUsersServiceSendTokenEmail,
IUsersServiceUpdate,
IUsersServiceUpdatePwd,
} from './interface/users.interface';
import { MailerService } from '@nestjs-modules/mailer';
import { sendTokenTemplate, welcomeTemplate } from 'src/commons/utils/utils';
Expand All @@ -40,12 +39,10 @@ export class UsersService {
private readonly mailerService: MailerService,
) {}

// 전체 조회하기
async findAll(): Promise<User[]> {
return await this.userRepository.find({});
}

// 하나 조회하기
async findOne({ userId }: IUsersServiceFindOne): Promise<User> {
const myUser = await this.userRepository.findOne({
where: { id: userId },
Expand All @@ -57,27 +54,23 @@ export class UsersService {
return myUser;
}

// 중복 계정 체크를 위한 이메일 조회
findOneByEmail({ email }: IUsersServiceFindOneByEmail): Promise<User> {
return this.userRepository.findOne({ where: { email } });
}

// 삭제된 유저 조회하기
findAllWithDeleted(): Promise<User[]> {
return this.userRepository.find({
withDeleted: true,
});
}

// 이메일 인증번호 전송
async sendTokenEmail({
email,
}: IUsersServiceSendTokenEmail): Promise<string> {
const token = String(Math.floor(Math.random() * 1000000)).padStart(6, '0');
// 이메일 정상인지 확인

this.checkValidationEmail({ email });
console.log(token);
// 이메일 인증번호 토큰 보내주기.

await this.mailerService.sendMail({
to: email,
from: process.env.EMAIL_USER,
Expand All @@ -96,7 +89,6 @@ export class UsersService {
return token;
}

// 이메일이 정상인지 확인
checkValidationEmail({ email }: IUsersServiceCheckValidationEmail) {
if (
email === undefined ||
Expand All @@ -109,7 +101,6 @@ export class UsersService {
}
}

// 이메일 중복검사
async duplicationEmail({
email,
}: IUsersServiceDuplicationEmail): Promise<boolean> {
Expand All @@ -121,24 +112,18 @@ export class UsersService {
}
}

// 회원가입
async create({
name, //
email,
password,
phone,
}: // image,
IUsersServiceCreate): Promise<User> {
//이메일 정상인지 확인
}: IUsersServiceCreate): Promise<User> {
await this.checkValidationEmail({ email });

// 비밀번호 암호화해주기
const hasedPassword = await bcrypt.hash(password, 10);

// 이메일 가입환영 템플릿 보내주기
await this.sendEmail({ email, name });

// 다시 리졸버로 값을 보내준다.
return this.userRepository.save({
name,
email,
Expand All @@ -147,16 +132,13 @@ export class UsersService {
});
}

// 로그인한 유저와 유저 댕댕이 프로필
async findUserDog({ email }: IUsersServiceFindUserDog): Promise<User> {
const result = await this.userRepository.findOne({
where: { email },
// relations: {dog:true},
});
return result;
}

// 가입환영 템플릿 만들어주기
async sendEmail({ email, name }: IUsersServiceSendEmail) {
const EMAIL_USER = process.env.EMAIL_USER;

Expand All @@ -175,7 +157,6 @@ export class UsersService {
return true;
}

// 회원 수정하기
async update({
userId, //
updateUserInput,
Expand All @@ -195,7 +176,6 @@ export class UsersService {
return result;
}

// 비밀번호 찾기(초기화하기)
async resetPassword({
email,
newPassword,
Expand All @@ -209,15 +189,13 @@ export class UsersService {
return await this.userRepository.save(theUser);
}

// 유저 삭제하기(삭제는 나중에)
async delete({
userId, //
}: IUsersServiceDelete) {
const result = await this.userRepository.softDelete({ id: userId });
return result.affected ? true : false;
}

// 이메일 인증번호 검증
async checkToken({ email, token }: IUsersServiceCheckToken) {
const myToken = await this.cacheManager.get(email);
return myToken === token ? true : false;
Expand Down