Skip to content

Commit d519019

Browse files
authored
Merge pull request #62 from oodd-team/dev
Dev
2 parents 97beccb + b1ae5d2 commit d519019

23 files changed

+137
-99
lines changed

src/app.module.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import { UserReportModule } from './user-report/user-report.module';
2121
import { AuthModule } from './auth/auth.module';
2222
import { DayjsModule } from './common/dayjs/dayjs.module'; // DayjsModule 추가
2323
import { EventsGateway } from './eventGateway';
24+
import { ConfigService } from '@nestjs/config';
25+
26+
const configService: ConfigService = new ConfigService();
2427

2528
@Module({
2629
imports: [
@@ -29,19 +32,19 @@ import { EventsGateway } from './eventGateway';
2932
}),
3033
TypeOrmModule.forRoot({
3134
type: 'mysql',
32-
host: process.env.DB_HOST,
35+
host: configService.get('DB_HOST'),
3336
port: 3306,
34-
username: process.env.DEV_DB_USER
35-
? process.env.DEV_DB_USER
36-
: process.env.DB_USER,
37-
password: process.env.DEV_DB_PASSWORD
38-
? process.env.DEV_DB_PASSWORD
39-
: process.env.DB_PASSWORD,
40-
database: process.env.DEV_DB_DATABASE
41-
? process.env.DEV_DB_DATABASE
42-
: process.env.DB_DATABASE, // 스키마 이름
37+
username: configService.get('DEV_DB_USER')
38+
? configService.get('DEV_DB_USER')
39+
: configService.get('DB_USER'),
40+
password: configService.get('DEV_DB_PASSWORD')
41+
? configService.get('DEV_DB_PASSWORD')
42+
: configService.get('DB_PASSWORD'),
43+
database: configService.get('DEV_DB_DATABASE')
44+
? configService.get('DEV_DB_DATABASE')
45+
: configService.get('DB_DATABASE'), // 스키마 이름
4346
entities: [__dirname + '/common/entities/*.entity.{js,ts}'], // 모델의 경로
44-
logging: true, // 정확히 어떤 sql 쿼리가 실행됐는지 로그 출력
47+
// logging: true, // 정확히 어떤 sql 쿼리가 실행됐는지 로그 출력
4548
synchronize: false, // 현재 entity 와 실제 데이터베이스 상 모델을 동기화
4649
}),
4750
UserModule,
@@ -61,10 +64,6 @@ import { EventsGateway } from './eventGateway';
6164
UserBlockModule,
6265
UserReportModule,
6366
AuthModule,
64-
65-
ConfigModule.forRoot({
66-
isGlobal: true,
67-
}),
6867
],
6968
controllers: [AppController],
7069
providers: [AppService, EventsGateway],

src/auth/auth.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { forwardRef, Inject, Injectable } from '@nestjs/common';
22
import { UserService } from 'src/user/user.service';
33
import { JwtPayload, SocialUser } from './dto/auth.dto';
44
import { JwtService } from '@nestjs/jwt';
5+
import { StatusEnum } from 'src/common/enum/entityStatus';
56

67
@Injectable()
78
export class AuthService {
@@ -41,7 +42,7 @@ export class AuthService {
4142
payload: JwtPayload,
4243
): Promise<JwtPayload | undefined> {
4344
return await this.userSerivce.findByFields({
44-
where: { id: payload.id, status: 'activated' },
45+
where: { id: payload.id, status: StatusEnum.ACTIVATED },
4546
});
4647
}
4748
}

src/auth/auth.swagger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseSwaggerDecorator } from 'nestjs-swagger-decorator';
2-
import { LoginResponse, UserDto } from './dto/auth.response';
2+
import { LoginResponse } from './dto/auth.response';
33
import { BaseResponse } from 'src/common/response/dto';
44
import { ErrorCodeVo } from 'src/common/exception/error';
55
import { ApiInternalServerErrorResponse } from '@nestjs/swagger';

src/auth/strategies/jwt.strategy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
1717
// accessToken 위치
1818
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
1919
ignoreExpiration: false,
20-
secretOrKey: process.env.JWT_SECRET,
20+
secretOrKey: configService.get('JWT_SECRET'),
2121
});
2222
}
2323

src/auth/strategies/kakao.strategy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { Request } from 'express';
99
export class JwtKakaoStrategy extends PassportStrategy(Strategy, 'kakao') {
1010
constructor(private configService: ConfigService) {
1111
super({
12-
clientID: process.env.KAKAO_ID, //.env파일에 들어있음\
13-
clientSecret: process.env.KAKAO_SECRET, //.env파일에 들어있음
14-
callbackURL: process.env.KAKAO_REDIRECT, //.env파일에 들어있음
12+
clientID: configService.get('KAKAO_ID'), //.env파일에 들어있음\
13+
clientSecret: configService.get('KAKAO_SECRET'), //.env파일에 들어있음
14+
callbackURL: configService.get('KAKAO_REDIRECT'), //.env파일에 들어있음
1515
passReqToCallback: true,
1616
});
1717
}

src/auth/strategies/naver.strategy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { Request } from 'express';
99
export class NaverStrategy extends PassportStrategy(Strategy, 'naver') {
1010
constructor(private configService: ConfigService) {
1111
super({
12-
clientID: process.env.NAVER_ID,
13-
clientSecret: process.env.NAVER_SECRET,
14-
callbackURL: process.env.NAVER_REDIRECT,
12+
clientID: configService.get('NAVER_ID'),
13+
clientSecret: configService.get('NAVER_SECRET'),
14+
callbackURL: configService.get('NAVER_REDIRECT'),
1515
passReqToCallback: true,
1616
});
1717
}

src/chat-message/chat-message.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
22
import { InjectRepository } from '@nestjs/typeorm';
33
import { ChatMessage } from 'src/common/entities/chat-message.entity';
44
import { ChatRoom } from 'src/common/entities/chat-room.entity';
5+
import { StatusEnum } from 'src/common/enum/entityStatus';
56
import { CreateMatchingReqeust } from 'src/matching/dto/matching.request';
67
import { QueryRunner, Repository } from 'typeorm';
78

@@ -53,7 +54,7 @@ export class ChatMessageService {
5354

5455
async getMessagesByChatRoomId(chatRoomId: number) {
5556
const messages = await this.chatMessageRepository.find({
56-
where: { chatRoom: { id: chatRoomId }, status: 'activated' },
57+
where: { chatRoom: { id: chatRoomId }, status: StatusEnum.ACTIVATED },
5758
order: { createdAt: 'ASC' }, // 오래된 메시지부터 최신 메시지 순으로 정렬
5859
relations: ['fromUser', 'toUser'], // 메시지 발신자, 수신자 정보도 함께 로드
5960
});

src/chat-room/chat-room.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
22
import { InjectRepository } from '@nestjs/typeorm';
33
import { ChatRoom } from 'src/common/entities/chat-room.entity';
44
import { Matching } from 'src/common/entities/matching.entity';
5+
import { StatusEnum } from 'src/common/enum/entityStatus';
56
import { DataNotFoundException } from 'src/common/exception/service.exception';
67
import { CreateMatchingReqeust } from 'src/matching/dto/matching.request';
78
import { Repository, QueryRunner } from 'typeorm';
@@ -82,7 +83,7 @@ export class ChatRoomService {
8283

8384
// 양쪽 사용자가 모두 나갔을 경우, 채팅방 비활성화
8485
if (chatRoom.fromUserLeavedAt && chatRoom.toUserLeavedAt) {
85-
chatRoom.status = 'deactivated';
86+
chatRoom.status = StatusEnum.DEACTIVATED;
8687
chatRoom.softDelete();
8788
}
8889

src/clothing/clothing.service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Clothing } from 'src/common/entities/clothing.entity';
55
import { UploadClothingDto } from 'src/post/dto/request/post.request';
66
import { DataNotFoundException } from 'src/common/exception/service.exception';
77
import { PatchClothingDto } from 'src/post/dto/request/post.request';
8+
import { StatusEnum } from 'src/common/enum/entityStatus';
89

910
@Injectable()
1011
export class ClothingService {
@@ -38,7 +39,7 @@ export class ClothingService {
3839
queryRunner: QueryRunner,
3940
): Promise<Clothing> {
4041
const existingClothing = await this.clothingRepository.findOne({
41-
where: { id: uploadClothingDto.id, status: 'activated' },
42+
where: { id: uploadClothingDto.id, status: StatusEnum.ACTIVATED },
4243
});
4344

4445
if (!existingClothing) {
@@ -66,7 +67,7 @@ export class ClothingService {
6667
clothing: Clothing,
6768
queryRunner: QueryRunner,
6869
): Promise<Clothing> {
69-
clothing.status = 'deactivated';
70+
clothing.status = StatusEnum.DEACTIVATED;
7071
clothing.softDelete();
7172
return await queryRunner.manager.save(clothing);
7273
}

src/common/entities/base.entity.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ import {
77
DeleteDateColumn,
88
BeforeUpdate,
99
} from 'typeorm';
10+
import { StatusEnum } from '../enum/entityStatus';
1011

1112
export abstract class BaseEntity {
1213
@PrimaryGeneratedColumn()
1314
id!: number;
1415

15-
@Column({ default: 'activated' })
16-
status!: 'activated' | 'deactivated';
16+
@Column({
17+
type: 'enum',
18+
enum: StatusEnum,
19+
default: StatusEnum.ACTIVATED,
20+
})
21+
status!: StatusEnum;
1722

1823
@CreateDateColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
1924
createdAt!: Date;

src/common/enum/entityStatus.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum StatusEnum {
2+
ACTIVATED = 'activated',
3+
DEACTIVATED = 'deactivated',
4+
}

src/matching/matching.controller.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
3939
import { PostService } from 'src/post/post.service';
4040
import { ChatRoomService } from 'src/chat-room/chat-room.service';
41+
import { StatusEnum } from 'src/common/enum/entityStatus';
4142

4243
@ApiBearerAuth('Authorization')
4344
@Controller('matching')
@@ -68,7 +69,7 @@ export class MatchingController {
6869
!(await this.postService.findByFields({
6970
where: {
7071
user: { id: body.requesterId },
71-
status: 'activated',
72+
status: StatusEnum.ACTIVATED,
7273
},
7374
}))
7475
) {

src/matching/matching.service.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ChatRoom } from 'src/common/entities/chat-room.entity';
1515
import { InjectRepository } from '@nestjs/typeorm';
1616
import { GetMatchingsResponse } from './dto/matching.response';
1717
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
18+
import { StatusEnum } from 'src/common/enum/entityStatus';
1819

1920
@Injectable()
2021
export class MatchingService {
@@ -34,12 +35,12 @@ export class MatchingService {
3435
{
3536
requester: { id: requesterId },
3637
target: { id: targetId },
37-
status: 'activated',
38+
status: StatusEnum.ACTIVATED,
3839
},
3940
{
4041
requester: { id: targetId },
4142
target: { id: requesterId },
42-
status: 'activated',
43+
status: StatusEnum.ACTIVATED,
4344
},
4445
],
4546
});
@@ -49,8 +50,8 @@ export class MatchingService {
4950
return await this.matchingRepository.find({
5051
relations: ['requester', 'target'],
5152
where: [
52-
{ requester: { id: currentUserId }, status: 'activated' },
53-
{ target: { id: currentUserId }, status: 'activated' },
53+
{ requester: { id: currentUserId }, status: StatusEnum.ACTIVATED },
54+
{ target: { id: currentUserId }, status: StatusEnum.ACTIVATED },
5455
],
5556
});
5657
}
@@ -194,13 +195,13 @@ export class MatchingService {
194195
requester: { id: requesterId },
195196
target: { id: targetId },
196197
requestStatus: MatchingRequestStatusEnum.ACCEPTED,
197-
status: 'activated',
198+
status: StatusEnum.ACTIVATED,
198199
},
199200
{
200201
requester: { id: targetId },
201202
target: { id: requesterId },
202203
requestStatus: MatchingRequestStatusEnum.ACCEPTED,
203-
status: 'activated',
204+
status: StatusEnum.ACTIVATED,
204205
},
205206
],
206207
});

src/post-clothing/post-clothing.service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ClothingService } from 'src/clothing/clothing.service';
44
import { Clothing } from 'src/common/entities/clothing.entity';
55
import { PostClothing } from 'src/common/entities/post-clothing.entity';
66
import { Post } from 'src/common/entities/post.entity';
7+
import { StatusEnum } from 'src/common/enum/entityStatus';
78
import { UploadClothingDto } from 'src/post/dto/request/post.request';
89
import { PatchClothingDto } from 'src/post/dto/request/post.request';
910
import { QueryRunner, Repository } from 'typeorm';
@@ -44,7 +45,7 @@ export class PostClothingService {
4445
queryRunner?: QueryRunner,
4546
): Promise<void> {
4647
const existingPostClothings = await this.postClothingRepository.find({
47-
where: { post: post, status: 'activated' },
48+
where: { post: post, status: StatusEnum.ACTIVATED },
4849
relations: ['clothing'],
4950
});
5051

@@ -109,7 +110,7 @@ export class PostClothingService {
109110
): Promise<void> {
110111
await Promise.all(
111112
postClothing.map(async (postClothingItem) => {
112-
postClothingItem.status = 'deactivated';
113+
postClothingItem.status = StatusEnum.DEACTIVATED;
113114
postClothingItem.softDelete();
114115

115116
await this.clothingService.deleteClothing(
@@ -134,7 +135,7 @@ export class PostClothingService {
134135

135136
await Promise.all(
136137
clothingToRemove.map(async (Postclothing) => {
137-
Postclothing.status = 'deactivated';
138+
Postclothing.status = StatusEnum.DEACTIVATED;
138139
Postclothing.softDelete();
139140
await this.clothingService.deleteClothing(
140141
Postclothing.clothing,

src/post-comment/post-comment.service.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'src/common/exception/service.exception';
1212
import { UserService } from 'src/user/user.service';
1313
import { PostService } from 'src/post/post.service';
14+
import { StatusEnum } from 'src/common/enum/entityStatus';
1415

1516
@Injectable()
1617
export class PostCommentService {
@@ -29,10 +30,10 @@ export class PostCommentService {
2930
createCommentDto: CreateCommentDto,
3031
): Promise<PostComment> {
3132
const post = await this.postService.findByFields({
32-
where: { id: postId, status: 'activated' },
33+
where: { id: postId, status: StatusEnum.ACTIVATED },
3334
});
3435
const user = await this.userService.findByFields({
35-
where: { id: currentUserId, status: 'activated' },
36+
where: { id: currentUserId, status: StatusEnum.ACTIVATED },
3637
});
3738
const postComment = this.postCommentRepository.create({
3839
content: createCommentDto.content,
@@ -54,7 +55,7 @@ export class PostCommentService {
5455

5556
await Promise.all(
5657
commentsToRemove.map(async (comment) => {
57-
comment.status = 'deactivated';
58+
comment.status = StatusEnum.DEACTIVATED;
5859
comment.softDelete();
5960
return queryRunner.manager.save(comment);
6061
}),
@@ -70,7 +71,7 @@ export class PostCommentService {
7071
const comment = await this.findCommentById(commentId);
7172

7273
try {
73-
comment.status = 'deactivated';
74+
comment.status = StatusEnum.DEACTIVATED;
7475
comment.softDelete();
7576

7677
await queryRunner.manager.save(comment);
@@ -92,8 +93,8 @@ export class PostCommentService {
9293
return await this.postCommentRepository.find({
9394
where: {
9495
post: { id: postId },
95-
status: 'activated',
96-
user: { status: 'activated', id: Not(In(blockedUserIds)) },
96+
status: StatusEnum.ACTIVATED,
97+
user: { status: StatusEnum.ACTIVATED, id: Not(In(blockedUserIds)) },
9798
},
9899
relations: ['user'],
99100
});
@@ -103,8 +104,8 @@ export class PostCommentService {
103104
const comment = await this.postCommentRepository.findOne({
104105
where: {
105106
id: commentId,
106-
status: 'activated',
107-
user: { status: 'activated' },
107+
status: StatusEnum.ACTIVATED,
108+
user: { status: StatusEnum.ACTIVATED },
108109
},
109110
relations: ['user'],
110111
});

src/post-image/post-image.service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Repository, QueryRunner } from 'typeorm';
55
import { Post } from 'src/common/entities/post.entity';
66
import { UploadImageDto } from 'src/post/dto/request/post.request';
77
import { InvalidInputValueException } from 'src/common/exception/service.exception';
8+
import { StatusEnum } from 'src/common/enum/entityStatus';
89

910
@Injectable()
1011
export class PostImageService {
@@ -94,7 +95,7 @@ export class PostImageService {
9495
): Promise<void> {
9596
await Promise.all(
9697
imagesToRemove.map(async (image) => {
97-
image.status = 'deactivated';
98+
image.status = StatusEnum.DEACTIVATED;
9899
image.softDelete();
99100
image.orderNum = 0;
100101
return queryRunner.manager.save(image);
@@ -113,7 +114,7 @@ export class PostImageService {
113114

114115
await Promise.all(
115116
imagesToRemove.map(async (image) => {
116-
image.status = 'deactivated';
117+
image.status = StatusEnum.DEACTIVATED;
117118
image.softDelete();
118119
image.orderNum = 0;
119120
return queryRunner.manager.save(image);

0 commit comments

Comments
 (0)