From 937dafca003c224624b4cba74eac6afbcad663ec Mon Sep 17 00:00:00 2001 From: Jjoobob123 <273hur4747@gmail.com> Date: Tue, 4 Apr 2023 12:03:40 +0900 Subject: [PATCH] =?UTF-8?q?user=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/users/user.resolver.ts | 10 ---------- src/apis/users/user.service.ts | 28 +++------------------------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/src/apis/users/user.resolver.ts b/src/apis/users/user.resolver.ts index 62e929f..b670679 100644 --- a/src/apis/users/user.resolver.ts +++ b/src/apis/users/user.resolver.ts @@ -12,13 +12,11 @@ export class UsersResolver { private readonly usersService: UsersService, // ) {} - // 전체 조회하기 @Query(() => [User], { description: ' Return: 전체 유저 정보 ' }) fetchUsers(): Promise { return this.usersService.findAll(); } - // 하나 조회하기 @Query(() => User, { description: ' Return: 유저 정보 ' }) fetchUser( @Args('userId') userId: string, // @@ -26,7 +24,6 @@ export class UsersResolver { return this.usersService.findOne({ userId }); } - // 삭제된 유저 조회하기 @Query(() => [User]) fetchUserWithDeleted(): Promise { return this.usersService.findAllWithDeleted(); @@ -39,7 +36,6 @@ export class UsersResolver { return this.usersService.duplicationEmail({ email }); } - // 로그인 된 유저 조회하기 (마이페이지가 들어가기 위함) @UseGuards(GqlAuthGuard('access')) @Query(() => User, { description: ' Return : 로그인한 유저, 유저 댕댕이 프로필', @@ -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, @@ -66,7 +61,6 @@ export class UsersResolver { }); } - // 회원 수정하기 @UseGuards(GqlAuthGuard('access')) @Mutation(() => User, { description: ' Return: 회원정보 업데이트 ' }) updateUser( @@ -77,7 +71,6 @@ export class UsersResolver { return this.usersService.update({ userId, updateUserInput }); } - // 비밀번호 찾기(초기화하기) @Mutation(() => User, { description: 'Return: 비밀번호 초기화하기(찾기)' }) resetPwd( @Args('email') email: string, // @@ -86,7 +79,6 @@ export class UsersResolver { return this.usersService.resetPassword({ email, newPassword }); } - // 이메일 인증번호 전송 @Mutation(() => String, { description: ' Return: 이메일 인증번호 전송 ' }) getTokenEmail( @Args('email') email: string, // @@ -94,7 +86,6 @@ export class UsersResolver { return this.usersService.sendTokenEmail({ email }); } - // 이메일 인증번호 검증 @Mutation(() => Boolean, { description: 'Return: 인증번호 검증' }) checkValidToken( @Args('email') email: string, // @@ -103,7 +94,6 @@ export class UsersResolver { return this.usersService.checkToken({ email, token }); } - // 유저 삭제하기 @Mutation(() => Boolean, { description: ' Return: 유저 정보 삭제하기 ' }) deleteUser( @Args('userId') userId: string, // diff --git a/src/apis/users/user.service.ts b/src/apis/users/user.service.ts index 5783661..9d665f3 100644 --- a/src/apis/users/user.service.ts +++ b/src/apis/users/user.service.ts @@ -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'; @@ -40,12 +39,10 @@ export class UsersService { private readonly mailerService: MailerService, ) {} - // 전체 조회하기 async findAll(): Promise { return await this.userRepository.find({}); } - // 하나 조회하기 async findOne({ userId }: IUsersServiceFindOne): Promise { const myUser = await this.userRepository.findOne({ where: { id: userId }, @@ -57,27 +54,23 @@ export class UsersService { return myUser; } - // 중복 계정 체크를 위한 이메일 조회 findOneByEmail({ email }: IUsersServiceFindOneByEmail): Promise { return this.userRepository.findOne({ where: { email } }); } - // 삭제된 유저 조회하기 findAllWithDeleted(): Promise { return this.userRepository.find({ withDeleted: true, }); } - // 이메일 인증번호 전송 async sendTokenEmail({ email, }: IUsersServiceSendTokenEmail): Promise { 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, @@ -96,7 +89,6 @@ export class UsersService { return token; } - // 이메일이 정상인지 확인 checkValidationEmail({ email }: IUsersServiceCheckValidationEmail) { if ( email === undefined || @@ -109,7 +101,6 @@ export class UsersService { } } - // 이메일 중복검사 async duplicationEmail({ email, }: IUsersServiceDuplicationEmail): Promise { @@ -121,24 +112,18 @@ export class UsersService { } } - // 회원가입 async create({ name, // email, password, phone, - }: // image, - IUsersServiceCreate): Promise { - //이메일 정상인지 확인 + }: IUsersServiceCreate): Promise { await this.checkValidationEmail({ email }); - // 비밀번호 암호화해주기 const hasedPassword = await bcrypt.hash(password, 10); - // 이메일 가입환영 템플릿 보내주기 await this.sendEmail({ email, name }); - // 다시 리졸버로 값을 보내준다. return this.userRepository.save({ name, email, @@ -147,16 +132,13 @@ export class UsersService { }); } - // 로그인한 유저와 유저 댕댕이 프로필 async findUserDog({ email }: IUsersServiceFindUserDog): Promise { 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; @@ -175,7 +157,6 @@ export class UsersService { return true; } - // 회원 수정하기 async update({ userId, // updateUserInput, @@ -195,7 +176,6 @@ export class UsersService { return result; } - // 비밀번호 찾기(초기화하기) async resetPassword({ email, newPassword, @@ -209,7 +189,6 @@ export class UsersService { return await this.userRepository.save(theUser); } - // 유저 삭제하기(삭제는 나중에) async delete({ userId, // }: IUsersServiceDelete) { @@ -217,7 +196,6 @@ export class UsersService { return result.affected ? true : false; } - // 이메일 인증번호 검증 async checkToken({ email, token }: IUsersServiceCheckToken) { const myToken = await this.cacheManager.get(email); return myToken === token ? true : false;