Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail #76

Closed
wants to merge 1 commit into from
Closed

fail #76

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
4 changes: 2 additions & 2 deletions be/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -15,7 +15,7 @@ import { JwtStrategy } from "./strategy/jwt.strategy";
expiresIn: 3600,
},
}),
forwardRef(() => UserModule),
UserModule,
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy],
Expand Down
8 changes: 1 addition & 7 deletions be/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"사용자가 등록되어 있지 않습니다. 회원가입을 진행해주세요"
Expand Down
4 changes: 2 additions & 2 deletions be/src/auth/strategy/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
}

async validate(payload: any) {
const { id } = payload;
const { nickName } = payload;

return { id };
return { nickName };
}
}
1 change: 0 additions & 1 deletion be/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 5 additions & 13 deletions be/src/user/dto/userInfo.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IsEmail,
IsInt,
MaxLength,
IsOptional,
} from "class-validator";

export class UserInfoDto {
Expand All @@ -21,7 +20,7 @@ export class UserInfoDto {

@ApiProperty({ example: "1234", description: "The password of the user" })
@IsString()
@IsOptional()
@IsNotEmpty()
@MaxLength(50)
password: string;

Expand All @@ -37,23 +36,16 @@ 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,
description: "The gender of the user. true is male, false is female",
})
@IsBoolean()
@IsNotEmpty()
isMale: boolean;
gender: boolean;
}
13 changes: 5 additions & 8 deletions be/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
120 changes: 4 additions & 116 deletions be/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 0 additions & 12 deletions be/src/user/user.decorator.ts

This file was deleted.

2 changes: 0 additions & 2 deletions be/src/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
89 changes: 1 addition & 88 deletions be/src/user/user.repository.ts
Original file line number Diff line number Diff line change
@@ -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<User> {
constructor(private dataSource: DataSource) {
Expand All @@ -20,90 +19,4 @@ export class UserRepository extends Repository<User> {
}
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,
};
}
}
Loading