Skip to content

Commit

Permalink
refactor(#316): modify enum name
Browse files Browse the repository at this point in the history
  • Loading branch information
hobiJeong committed Mar 7, 2024
1 parent b3c3b8f commit de1e423
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/admins/dtos/user-response-for-admin.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, OmitType } from '@nestjs/swagger';
import { Provider } from '@src/auth/enums/provider.enum';
import { UserProvider } from '@src/auth/enums/user-provider.enum';
import { UserStatus } from '@src/users/constants/user-status.enum';
import { UserInfoDto } from '@src/users/dtos/user-info.dto';

Expand All @@ -17,9 +17,9 @@ export class UserResponseForAdminDto extends OmitType(UserInfoDto, [

@ApiProperty({
description: '유저 정보 제공자',
enum: Provider,
enum: UserProvider,
})
provider: Provider;
provider: UserProvider;

@ApiProperty({
description: '유저 상태',
Expand Down
14 changes: 7 additions & 7 deletions src/auth/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ApiNaverLogin } from '@src/auth/swagger-decorators/naver-login.decorato
import { ApiNaverLogout } from '@src/auth/swagger-decorators/naver-logout.decorator';
import { ApiNaverUnlink } from '@src/auth/swagger-decorators/naver-unlink.decorator';
import { ApiNewAccessToken } from '@src/auth/swagger-decorators/new-access-token.decorator';
import { Provider } from '@src/auth/enums/provider.enum';
import { UserProvider } from '@src/auth/enums/user-provider.enum';
import { AuthService } from '@src/auth/services/auth.service';

@Controller('auth')
Expand All @@ -48,7 +48,7 @@ export class AuthController {
throw new BadRequestException('인가코드가 없습니다.');
}

return this.authService.login(code, Provider.Naver);
return this.authService.login(code, UserProvider.Naver);
}

@ApiKakaoLogin()
Expand All @@ -59,7 +59,7 @@ export class AuthController {
throw new BadRequestException('인가코드가 없습니다.');
}

return this.authService.login(code, Provider.Kakao);
return this.authService.login(code, UserProvider.Kakao);
}

@ApiGoogleLogin()
Expand All @@ -70,7 +70,7 @@ export class AuthController {
throw new BadRequestException('인가코드가 없습니다.');
}

return this.authService.login(code, Provider.Google);
return this.authService.login(code, UserProvider.Google);
}

@ApiNewAccessToken()
Expand Down Expand Up @@ -102,7 +102,7 @@ export class AuthController {
await this.tokenService.deleteTokens(userId);

return this.authService.unlink(
Provider.Kakao,
UserProvider.Kakao,
socialAccessToken,
socialRefreshToken,
);
Expand All @@ -125,7 +125,7 @@ export class AuthController {
await this.tokenService.deleteTokens(userId);

return this.authService.unlink(
Provider.Naver,
UserProvider.Naver,
socialAccessToken,
socialRefreshToken,
);
Expand All @@ -146,7 +146,7 @@ export class AuthController {

await this.tokenService.deleteTokens(userId);

return this.authService.unlink(Provider.Google, socialAccessToken);
return this.authService.unlink(UserProvider.Google, socialAccessToken);
}

@ApiDeleteAccount()
Expand Down
5 changes: 5 additions & 0 deletions src/auth/enums/user-provider.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum UserProvider {
Naver = 'naver',
Kakao = 'kakao',
Google = 'google',
}
4 changes: 2 additions & 2 deletions src/auth/interfaces/user-info.interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Provider } from '@src/auth/enums/provider.enum';
import { UserProvider } from '@src/auth/enums/user-provider.enum';

export interface UserInfo {
uniqueId: string;
provider: Provider;
provider: UserProvider;
name: string;
email: string;
}
30 changes: 15 additions & 15 deletions src/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { UserService } from '@src/users/services/user.service';
import { UserImageService } from '@src/users/services/user-image.service';
import { UserStatus } from '@src/users/constants/user-status.enum';
import { UserInfo } from '@src/auth/interfaces/user-info.interface';
import { Provider } from '@src/auth/enums/provider.enum';
import { UserProvider } from '@src/auth/enums/user-provider.enum';
import { TokenService } from '@src/auth/services/token.service';
import { AuthServiceInterface } from '@src/auth/interfaces/auth-service.interface';
import { BannedUserException } from '@src/http-exceptions/exceptions/banned-user.exception';
Expand All @@ -33,15 +33,15 @@ export class AuthService implements AuthServiceInterface {
private readonly userIntroService: UserIntroService,
) {}

async login(authorizeCode: string, provider: Provider) {
async login(authorizeCode: string, provider: UserProvider) {
try {
let tokenUrl: string,
tokenHeader: object,
tokenBody: object,
userInfoUrl: string,
userInfoHeader: object;

if (provider === Provider.Naver) {
if (provider === UserProvider.Naver) {
// 네이버 토큰 발급
tokenUrl = 'https://nid.naver.com/oauth2.0/token';
tokenHeader = {
Expand All @@ -57,7 +57,7 @@ export class AuthService implements AuthServiceInterface {
state: 'test',
redirect_uri: process.env.NAVER_REDIRECT_URI,
};
} else if (provider === Provider.Kakao) {
} else if (provider === UserProvider.Kakao) {
// 카카오 토큰 발급
tokenUrl = 'https://kauth.kakao.com/oauth/token';
tokenHeader = {
Expand All @@ -71,7 +71,7 @@ export class AuthService implements AuthServiceInterface {
redirect_uri: process.env.KAKAO_REDIRECT_URI,
code: authorizeCode,
};
} else if (provider === Provider.Google) {
} else if (provider === UserProvider.Google) {
// 구글 토큰 발급
tokenUrl = 'https://oauth2.googleapis.com/token';
tokenHeader = {
Expand All @@ -93,15 +93,15 @@ export class AuthService implements AuthServiceInterface {
const socialAccessToken = token.access_token;
const socialRefreshToken = token.refresh_token;

if (provider === Provider.Naver) {
if (provider === UserProvider.Naver) {
// 네이버 로그인 사용자 정보 조회
userInfoUrl = 'https://openapi.naver.com/v1/nid/me';
userInfoHeader = {
headers: {
Authorization: `Bearer ${socialAccessToken}`,
},
};
} else if (provider === Provider.Kakao) {
} else if (provider === UserProvider.Kakao) {
// 카카오 로그인 사용자 정보 조회
userInfoUrl = 'https://kapi.kakao.com/v2/user/me';
userInfoHeader = {
Expand All @@ -110,7 +110,7 @@ export class AuthService implements AuthServiceInterface {
'Content-type': 'application/x-www-form-urlencoded;charset=utf-8',
},
};
} else if (provider === Provider.Google) {
} else if (provider === UserProvider.Google) {
// 구글 로그인 사용자 정보 조회
userInfoUrl = 'https://www.googleapis.com/oauth2/v2/userinfo';
userInfoHeader = {
Expand All @@ -129,17 +129,17 @@ export class AuthService implements AuthServiceInterface {
let profileImage = null;
let uniqueId = null;

if (provider === Provider.Naver) {
if (provider === UserProvider.Naver) {
name = socialUserInfo.response.nickname; // 네이버 닉네임
email = socialUserInfo.response.email; // 네이버 이메일
profileImage = socialUserInfo.response.profile_image; // 네이버 프로필 이미지
uniqueId = socialUserInfo.response.id; // 네이버 고유 아이디
} else if (provider === Provider.Kakao) {
} else if (provider === UserProvider.Kakao) {
name = socialUserInfo.kakao_account.profile.nickname; // 카카오 닉네임
email = socialUserInfo.kakao_account.email; // 카카오 이메일
profileImage = socialUserInfo.kakao_account.profile.profile_image_url; // 카카오 프로필 이미지
uniqueId = socialUserInfo.id; // 카카오 고유 아이디
} else if (provider === Provider.Google) {
} else if (provider === UserProvider.Google) {
name = socialUserInfo.name; // Google 닉네임
email = socialUserInfo.email; // Google 이메일
profileImage = socialUserInfo.picture; // Google 프로필 이미지
Expand Down Expand Up @@ -354,7 +354,7 @@ export class AuthService implements AuthServiceInterface {
}

async unlink(
provider: Provider,
provider: UserProvider,
accessToken: string,
refreshToken?: string,
): Promise<object> {
Expand All @@ -364,7 +364,7 @@ export class AuthService implements AuthServiceInterface {
unlinkHeader: object,
unlinkBody: object;

if (provider === Provider.Kakao) {
if (provider === UserProvider.Kakao) {
checkValidAccessToken =
await this.tokenService.checkValidKakaoToken(accessToken);

Expand All @@ -380,7 +380,7 @@ export class AuthService implements AuthServiceInterface {
},
};
unlinkBody = {};
} else if (provider === Provider.Naver) {
} else if (provider === UserProvider.Naver) {
checkValidAccessToken =
await this.tokenService.checkValidNaverToken(accessToken);

Expand All @@ -401,7 +401,7 @@ export class AuthService implements AuthServiceInterface {
grant_type: 'delete',
service_provider: 'NAVER',
};
} else if (provider === Provider.Google) {
} else if (provider === UserProvider.Google) {
unlinkUrl = `https://accounts.google.com/o/oauth2/revoke?token=${accessToken}`;
unlinkHeader = {};
unlinkBody = {};
Expand Down
4 changes: 2 additions & 2 deletions src/users/dtos/user-info.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Exclude } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { UserStatus } from '@src/users/constants/user-status.enum';
import { Provider } from '@src/auth/enums/provider.enum';
import { UserProvider } from '@src/auth/enums/user-provider.enum';
import { UserRole } from '@src/users/constants/user-role.enum';
import { User } from '@src/users/entities/user.entity';

Expand Down Expand Up @@ -80,7 +80,7 @@ export class UserInfoDto
description: '정보 제공자',
})
@Exclude()
provider: Provider;
provider: UserProvider;

@Exclude()
status: UserStatus;
Expand Down
2 changes: 1 addition & 1 deletion src/users/repositories/user-badge.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { EntityManager } from 'typeorm';
import { BadgeList } from '@src/common/entity/badge-list.entity';
import { BadgeList } from '@src/common/entity/badge.entity';
import { UserBadge } from '@src/users/entities/user-badge.entity';

@Injectable()
Expand Down
6 changes: 3 additions & 3 deletions src/users/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
UpdateResult,
} from 'typeorm';
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
import { Provider } from '@src/auth/enums/provider.enum';
import { UserProvider } from '@src/auth/enums/user-provider.enum';
import { UserInfo } from '@src/auth/interfaces/user-info.interface';
import { User } from '@src/users/entities/user.entity';

Expand Down Expand Up @@ -39,7 +39,7 @@ export class UserRepository {
).rank;
}

findUser(uniqueId: string, provider: Provider): Promise<User | null> {
findUser(uniqueId: string, provider: UserProvider): Promise<User | null> {
return this.entityManager.findOne(User, { where: { uniqueId, provider } });
}

Expand Down Expand Up @@ -90,7 +90,7 @@ export class UserRepository {
.getOne();
}

findOneAndSelectAllByQueryBuilder(email: string, provider: Provider) {
findOneAndSelectAllByQueryBuilder(email: string, provider: UserProvider) {
return this.entityManager
.getRepository(User)
.createQueryBuilder('user')
Expand Down
6 changes: 3 additions & 3 deletions src/users/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
import { EntityManager, FindManyOptions, FindOneOptions } from 'typeorm';
import { plainToInstance } from 'class-transformer';
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
import { Provider } from '@src/auth/enums/provider.enum';
import { UserProvider } from '@src/auth/enums/user-provider.enum';
import { UserInfo } from '@src/auth/interfaces/user-info.interface';
import { UserBadgeRepository } from '@src/users/repositories/user-badge.repository';
import { UserIntroRepository } from '@src/users/repositories/user-intro.repository';
Expand All @@ -26,7 +26,7 @@ export class UserService {
return this.userRepository.findAll(options);
}

findUser(uniqueId: string, provider: Provider) {
findUser(uniqueId: string, provider: UserProvider) {
return this.userRepository.findUser(uniqueId, provider);
}

Expand All @@ -40,7 +40,7 @@ export class UserService {
return existUser;
}

findOneAndSelectAllByQueryBuilder(email: string, provider: Provider) {
findOneAndSelectAllByQueryBuilder(email: string, provider: UserProvider) {
return this.userRepository.findOneAndSelectAllByQueryBuilder(
email,
provider,
Expand Down

0 comments on commit de1e423

Please sign in to comment.