diff --git a/be/src/auth/auth.module.ts b/be/src/auth/auth.module.ts index 1c8ec35..1259572 100644 --- a/be/src/auth/auth.module.ts +++ b/be/src/auth/auth.module.ts @@ -1,4 +1,4 @@ -import { Module, forwardRef } from "@nestjs/common"; +import { Module } from "@nestjs/common"; import { AuthController } from "./auth.controller"; import { AuthService } from "./auth.service"; import { JwtModule } from "@nestjs/jwt"; @@ -15,7 +15,7 @@ import { JwtStrategy } from "./strategy/jwt.strategy"; expiresIn: 3600, }, }), - forwardRef(() => UserModule), + UserModule, ], controllers: [AuthController], providers: [AuthService, JwtStrategy], diff --git a/be/src/auth/auth.service.ts b/be/src/auth/auth.service.ts index dce87db..e4f16d5 100644 --- a/be/src/auth/auth.service.ts +++ b/be/src/auth/auth.service.ts @@ -44,14 +44,8 @@ export class AuthService { if (user) { const payload = { nickName: user.nickName }; const accessToken = this.jwtService.sign(payload); - - const refreshToken = this.jwtService.sign(payload, { - secret: "nibobnebob", - expiresIn: '7d', - }); - - return { accessToken, refreshToken }; + return accessToken; } else { throw new NotFoundException( "사용자가 등록되어 있지 않습니다. 회원가입을 진행해주세요" diff --git a/be/src/auth/strategy/jwt.strategy.ts b/be/src/auth/strategy/jwt.strategy.ts index 01e1e67..b13b68c 100644 --- a/be/src/auth/strategy/jwt.strategy.ts +++ b/be/src/auth/strategy/jwt.strategy.ts @@ -12,8 +12,8 @@ export class JwtStrategy extends PassportStrategy(Strategy) { } async validate(payload: any) { - const { id } = payload; + const { nickName } = payload; - return { id }; + return { nickName }; } } diff --git a/be/src/main.ts b/be/src/main.ts index d82366b..49d88cf 100644 --- a/be/src/main.ts +++ b/be/src/main.ts @@ -14,7 +14,6 @@ async function bootstrap() { .setTitle("Example API") .setDescription("The example API description") .setVersion("1.0") - .addBearerAuth() .addTag("example") .build(); const document = SwaggerModule.createDocument(app, config); diff --git a/be/src/user/dto/userInfo.dto.ts b/be/src/user/dto/userInfo.dto.ts index 4805a8a..9bf6f83 100644 --- a/be/src/user/dto/userInfo.dto.ts +++ b/be/src/user/dto/userInfo.dto.ts @@ -6,7 +6,6 @@ import { IsEmail, IsInt, MaxLength, - IsOptional, } from "class-validator"; export class UserInfoDto { @@ -21,7 +20,7 @@ export class UserInfoDto { @ApiProperty({ example: "1234", description: "The password of the user" }) @IsString() - @IsOptional() + @IsNotEmpty() @MaxLength(50) password: string; @@ -37,17 +36,10 @@ export class UserInfoDto { @MaxLength(20) nickName: string; - @ApiProperty({ example: "강동구", description: "The region of the user" }) - @IsString() - @IsNotEmpty() - @MaxLength(20) - region: string; - - @ApiProperty({ example: "1234/56/78", description: "The birth of the user" }) - @IsString() - @MaxLength(11) + @ApiProperty({ example: 20, description: "The age of the user" }) + @IsInt() @IsNotEmpty() - birthdate: string; + age: number; @ApiProperty({ example: true, @@ -55,5 +47,5 @@ export class UserInfoDto { }) @IsBoolean() @IsNotEmpty() - isMale: boolean; + gender: boolean; } diff --git a/be/src/user/entities/user.entity.ts b/be/src/user/entities/user.entity.ts index 286c90e..eec0cdc 100644 --- a/be/src/user/entities/user.entity.ts +++ b/be/src/user/entities/user.entity.ts @@ -15,23 +15,20 @@ export class User { @Column({ type: "varchar", length: 20, unique: true }) nickName: string; - @Column({ type: "varchar", length: 50, unique: true }) + @Column({ type: "varchar", length: 50 }) email: string; - @Column({ type: "varchar", length: 11 }) - birthdate: string; - - @Column({ type: "varchar", length: 20 }) - region: string; + @Column({ type: "int" }) + age: number; @Column({ type: "boolean" }) - isMale: boolean; + gender: boolean; @Column({ type: "varchar", length: 50, nullable: true }) password: string | null; @Column({ type: "varchar", length: 20, nullable: true }) - provider: string | null; + social_provider: string | null; @CreateDateColumn({ type: "timestamp" }) created_at: Date; diff --git a/be/src/user/user.controller.ts b/be/src/user/user.controller.ts index debd4b9..ee71b73 100644 --- a/be/src/user/user.controller.ts +++ b/be/src/user/user.controller.ts @@ -2,136 +2,24 @@ import { Body, Controller, Get, - Param, Post, - Put, - Delete, UsePipes, ValidationPipe, - UseGuards, } from "@nestjs/common"; -import { - ApiBearerAuth, - ApiOperation, - ApiParam, - ApiResponse, -} from "@nestjs/swagger"; +import { ApiOperation, ApiResponse } from "@nestjs/swagger"; import { UserInfoDto } from "./dto/userInfo.dto"; import { UserService } from "./user.service"; -import { GetUser, TokenInfo } from "./user.decorator"; -import { AuthGuard } from "@nestjs/passport"; @Controller("user") export class UserController { - constructor(private userService: UserService) { } - - @Get() - @UseGuards(AuthGuard("jwt")) - @ApiBearerAuth() - @ApiOperation({ summary: "마이페이지 유저 수정페이지 정보 가져오기" }) - @ApiResponse({ - status: 200, - description: "마이페이지 수정페이지 정보 요청 성공", - }) - @ApiResponse({ status: 401, description: "인증 실패" }) - @ApiResponse({ status: 400, description: "부적절한 요청" }) - async getMypageUserDetailInfo(@GetUser() tokenInfo: TokenInfo) { - return await this.userService.getMypageUserDetailInfo(tokenInfo); - } - - @Get(":nickname/details") - @UseGuards(AuthGuard("jwt")) - @ApiBearerAuth() - @ApiParam({ - name: "nickname", - required: true, - description: "요청하고자 하는 유저의 닉네임", - type: String, - }) - @ApiOperation({ summary: "유저 정보 가져오기" }) - @ApiResponse({ status: 200, description: "정보 요청 성공" }) - @ApiResponse({ status: 401, description: "인증 실패" }) - @ApiResponse({ status: 400, description: "부적절한 요청" }) - async getUserInfo(@Param("nickname") nickname: UserInfoDto["nickName"]) { - return await this.userService.getUserInfo(nickname); - } - - @Get("/details") - @UseGuards(AuthGuard("jwt")) - @ApiBearerAuth() - @ApiOperation({ summary: "마이페이지 유저 정보 가져오기" }) - @ApiResponse({ status: 200, description: "마이페이지 정보 요청 성공" }) - @ApiResponse({ status: 401, description: "인증 실패" }) - @ApiResponse({ status: 400, description: "부적절한 요청" }) - async getMypageUserInfo(@GetUser() tokenInfo: TokenInfo) { - return await this.userService.getMypageUserInfo(tokenInfo); - } - - @Get("nickname/:nickname/exists") - @ApiParam({ - name: "nickname", - required: true, - description: "확인하고자 하는 닉네임", - type: String, - }) - @ApiOperation({ summary: "닉네임 중복확인" }) - @ApiResponse({ status: 200, description: "닉네임 중복확인 요청 성공" }) - @ApiResponse({ status: 400, description: "부적절한 요청" }) - async getNickNameAvailability( - @Param("nickname") nickname: UserInfoDto["nickName"] - ) { - return await this.userService.getNickNameAvailability(nickname); - } - - @Get("email/:email/exists") - @ApiParam({ - name: "email", - required: true, - description: "확인하고자 하는 이메일", - type: String, - }) - @ApiOperation({ summary: "이메일 중복확인" }) - @ApiResponse({ status: 200, description: "이메일 중복확인 요청 성공" }) - @ApiResponse({ status: 400, description: "부적절한 요청" }) - async getEmailAvailability( - @Param("email") email: UserInfoDto["email"] - ) { - return await this.userService.getEmailAvailability(email); - } + constructor(private userService: UserService) {} @Post() @ApiOperation({ summary: "유저 회원가입" }) @ApiResponse({ status: 200, description: "회원가입 성공" }) @ApiResponse({ status: 400, description: "부적절한 요청" }) @UsePipes(new ValidationPipe()) - async singup(@Body() userInfoDto: UserInfoDto) { - return await this.userService.signup(userInfoDto); - } - - @Delete() - @UseGuards(AuthGuard("jwt")) - @ApiBearerAuth() - @ApiOperation({ summary: "유저 회원탈퇴" }) - @ApiResponse({ status: 200, description: "회원탈퇴 성공" }) - @ApiResponse({ status: 401, description: "인증 실패" }) - @ApiResponse({ status: 400, description: "부적절한 요청" }) - @UsePipes(new ValidationPipe()) - async deleteUserAccount(@GetUser() tokenInfo: TokenInfo) { - return await this.userService.deleteUserAccount(tokenInfo); - } - - @Put() - @UseGuards(AuthGuard("jwt")) - @ApiBearerAuth() - @ApiOperation({ summary: "유저 회원정보 수정" }) - @ApiResponse({ status: 200, description: "회원정보 수정 성공" }) - @ApiResponse({ status: 401, description: "인증 실패" }) - @ApiResponse({ status: 400, description: "부적절한 요청" }) - @UsePipes(new ValidationPipe()) - async updateMypageUserInfo( - @GetUser() tokenInfo: TokenInfo, - @Body() userInfoDto: UserInfoDto - ) { - return await this.userService.updateMypageUserInfo(tokenInfo, userInfoDto); + singup(@Body() userInfoDto: UserInfoDto) { + return this.userService.signup(userInfoDto); } } diff --git a/be/src/user/user.decorator.ts b/be/src/user/user.decorator.ts deleted file mode 100644 index 38b3c82..0000000 --- a/be/src/user/user.decorator.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ExecutionContext, createParamDecorator } from "@nestjs/common"; - -export interface TokenInfo { - id: number; -} - -export const GetUser = createParamDecorator( - (data, ctx: ExecutionContext): TokenInfo => { - const req = ctx.switchToHttp().getRequest(); - return req.user; - } -); diff --git a/be/src/user/user.module.ts b/be/src/user/user.module.ts index fb5e688..2c3ad53 100644 --- a/be/src/user/user.module.ts +++ b/be/src/user/user.module.ts @@ -2,10 +2,8 @@ import { Module } from "@nestjs/common"; import { UserController } from "./user.controller"; import { UserService } from "./user.service"; import { UserRepository } from "./user.repository"; -import { AuthModule } from "src/auth/auth.module"; @Module({ - imports: [AuthModule], controllers: [UserController], providers: [UserService, UserRepository], exports: [UserRepository], diff --git a/be/src/user/user.repository.ts b/be/src/user/user.repository.ts index 080eb58..c43b3b5 100644 --- a/be/src/user/user.repository.ts +++ b/be/src/user/user.repository.ts @@ -1,9 +1,8 @@ -import { DataSource, IsNull, Repository, Not } from "typeorm"; +import { DataSource, Repository } from "typeorm"; import { User } from "./entities/user.entity"; import { UserInfoDto } from "./dto/userInfo.dto"; import { ConflictException, Injectable } from "@nestjs/common"; - @Injectable() export class UserRepository extends Repository { constructor(private dataSource: DataSource) { @@ -20,90 +19,4 @@ export class UserRepository extends Repository { } return; } - async getNickNameAvailability(nickName: UserInfoDto["nickName"]) { - const user = await this.findOne({ - select: ["nickName"], - where: { nickName: nickName }, - }); - return { isexist: user !== null }; - } - async getEmailAvailability(email: UserInfoDto["email"]) { - const user = await this.findOne({ - select: ["email"], - where: { email: email }, - }); - return { isexist: user !== null }; - } - async getMypageUserInfo(id: number) { - const userInfo = await this.findOne({ - select: ["nickName", "birthdate", "isMale", "region"], - where: { id: id }, - }); - return { userInfo: userInfo }; - } - async getUserInfo(nickName: UserInfoDto["nickName"]) { - const userInfo = await this.findOne({ - select: ["nickName", "birthdate", "isMale", "region"], - where: { nickName: nickName, deleted_at: IsNull() }, - }); - return { userInfo: userInfo }; - } - async getMypageUserDetailInfo(id: number) { - const userInfo = await this.findOne({ - select: [ - "nickName", - "birthdate", - "isMale", - "region", - "provider", - "email", - ], - where: { id: id }, - }); - return { userInfo: userInfo }; - } - async deleteUserAccount(id: number) { - const userInfo = await this.findOne({ - select: ["id"], - where: { id: id }, - }); - if (userInfo) { - await this.update(userInfo.id, { deleted_at: new Date() }); - } else { - throw new ConflictException("Already Deleted"); - } - return {}; - } - async updateMypageUserInfo(id: number, userInfoDto: UserInfoDto) { - const user = await this.findOne({ select: ["id"], where: { id: id } }); - const [emailUser, nickNameUser] = await Promise.all([ - this.findOne({ select: ["id"], where: { email: userInfoDto["email"] } }), - this.findOne({ - select: ["id"], where: { nickName: userInfoDto["nickName"] }, - }), - ]); - - const isEmailDuplicate = !!emailUser; - const isNickNameDuplicate = !!nickNameUser; - - let updateObject = { - birthdate: userInfoDto["birthdate"], - isMale: userInfoDto["isMale"], - region: userInfoDto["region"], - provider: userInfoDto["provider"], - password: userInfoDto["password"], - }; - - if (!isEmailDuplicate) { - updateObject["email"] = userInfoDto["email"]; - } - if (!isNickNameDuplicate) { - updateObject["nickName"] = userInfoDto["nickName"]; - } - await this.update(user.id, updateObject); - return { - isEmailDuplicate: isEmailDuplicate, - isNickNameDuplicate: isNickNameDuplicate, - }; - } } diff --git a/be/src/user/user.service.ts b/be/src/user/user.service.ts index 5bfca8b..53056bc 100644 --- a/be/src/user/user.service.ts +++ b/be/src/user/user.service.ts @@ -2,39 +2,14 @@ import { Injectable } from "@nestjs/common"; import { UserInfoDto } from "./dto/userInfo.dto"; import { InjectRepository } from "@nestjs/typeorm"; import { UserRepository } from "./user.repository"; -import { TokenInfo } from "./user.decorator"; @Injectable() export class UserService { constructor( @InjectRepository(UserRepository) private usersRepository: UserRepository - ) { } - async signup(userInfoDto: UserInfoDto) { - return await this.usersRepository.createUser(userInfoDto); - } - async getNickNameAvailability(nickName: UserInfoDto["nickName"]) { - return await this.usersRepository.getNickNameAvailability(nickName); - } - async getEmailAvailability(email: UserInfoDto["email"]) { - return await this.usersRepository.getEmailAvailability(email); - } - async getMypageUserInfo(tokenInfo: TokenInfo) { - return await this.usersRepository.getMypageUserInfo(tokenInfo.id); - } - async getUserInfo(nickName: UserInfoDto["nickName"]) { - return await this.usersRepository.getUserInfo(nickName); - } - async getMypageUserDetailInfo(tokenInfo: TokenInfo) { - return await this.usersRepository.getMypageUserDetailInfo(tokenInfo.id); - } - async deleteUserAccount(tokenInfo: TokenInfo) { - return await this.usersRepository.deleteUserAccount(tokenInfo.id); - } - async updateMypageUserInfo(tokenInfo: TokenInfo, userInfoDto: UserInfoDto) { - return await this.usersRepository.updateMypageUserInfo( - tokenInfo.id, - userInfoDto - ); + ) {} + signup(userInfoDto: UserInfoDto) { + return this.usersRepository.createUser(userInfoDto); } }