Skip to content

Commit 361be68

Browse files
authored
Merge pull request #72 from oodd-team/OD-174
매칭 예외 처리 OD-174
2 parents 686c83f + 9745513 commit 361be68

File tree

10 files changed

+77
-46
lines changed

10 files changed

+77
-46
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class ChatRoomService {
7777
fromUser: { id: body.requesterId },
7878
toUser: { id: body.targetId },
7979
matching: matching,
80-
requestStatus: 'pending',
80+
requestStatus: MatchingRequestStatusEnum.PENDING,
8181
});
8282
}
8383

src/matching/dto/matching.response.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ class RepresentativePost {
4545
{ url: 'https://example.com/image2.jpg', orderNum: 2 },
4646
],
4747
})
48-
postImages: { url: string; orderNum: number }[];
48+
postImages?: { url: string; orderNum: number }[];
4949

5050
@ApiProperty({
5151
description: '매칭 요청자의 게시물 스타일 태그 목록',
5252
type: [String],
5353
example: ['classic', 'basic'],
5454
})
55-
styleTags: string[];
55+
styleTags?: string[];
5656
}
5757
class RequesterResponse {
5858
@ApiProperty({
@@ -78,7 +78,7 @@ class RequesterResponse {
7878
type: RepresentativePost,
7979
})
8080
@Type(() => RepresentativePost)
81-
representativePost: RepresentativePost;
81+
representativePost?: RepresentativePost;
8282
}
8383

8484
class Matching {

src/matching/matching.module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { ChatMessageModule } from 'src/chat-message/chat-message.module';
77
import { ChatRoomModule } from 'src/chat-room/chat-room.module';
88
import { UserModule } from 'src/user/user.module';
99
import { PostModule } from 'src/post/post.module';
10+
import { UserBlock } from 'src/common/entities/user-block.entity';
11+
import { UserBlockModule } from 'src/user-block/user-block.module';
1012

1113
@Module({
1214
imports: [
@@ -15,6 +17,7 @@ import { PostModule } from 'src/post/post.module';
1517
ChatRoomModule,
1618
forwardRef(() => UserModule),
1719
PostModule,
20+
UserBlockModule,
1821
],
1922
controllers: [MatchingController],
2023
providers: [MatchingService],

src/matching/matching.service.ts

+25-16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { InjectRepository } from '@nestjs/typeorm';
1313
import { GetMatchingsResponse } from './dto/matching.response';
1414
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
1515
import { StatusEnum } from 'src/common/enum/entityStatus';
16+
import { UserBlockService } from 'src/user-block/user-block.service';
1617

1718
@Injectable()
1819
export class MatchingService {
@@ -22,6 +23,7 @@ export class MatchingService {
2223
private readonly chatRoomService: ChatRoomService,
2324
private readonly chatMessageService: ChatMessageService,
2425
private readonly dataSource: DataSource,
26+
private readonly userBlockService: UserBlockService,
2527
) {}
2628

2729
async getMatchingsByCurrentId(currentUserId: number): Promise<Matching[]> {
@@ -103,6 +105,8 @@ export class MatchingService {
103105
}
104106

105107
async getMatchings(currentUserId: number): Promise<GetMatchingsResponse> {
108+
const blockedUserIds =
109+
await this.userBlockService.getBlockedUserIdsByRequesterId(currentUserId);
106110
const matchings = await this.matchingRepository
107111
.createQueryBuilder('matching')
108112
.leftJoinAndSelect('matching.requester', 'requester')
@@ -120,12 +124,15 @@ export class MatchingService {
120124
.andWhere('requester.status = :activated', {
121125
activated: StatusEnum.ACTIVATED,
122126
})
123-
.orderBy(
124-
// 우선순위: isRepresentative가 true인 게시물 먼저, 그 다음은 최신 게시물
125-
'CASE WHEN post.isRepresentative = true THEN 0 ELSE 1 END',
126-
'ASC',
127+
.andWhere(
128+
blockedUserIds.length > 0
129+
? 'requester.id NOT IN (:...blockedUserIds)'
130+
: '1=1',
131+
{ blockedUserIds },
127132
)
128-
.addOrderBy('post.createdAt', 'DESC')
133+
.orderBy('matching.createdAt', 'DESC')
134+
.addOrderBy('post.isRepresentative', 'DESC') // 'isRepresentative'가 true인 게시물을 우선적으로 정렬
135+
.addOrderBy('post.createdAt', 'DESC') // 그 다음은 최신 게시물 우선으로 정렬
129136
.getMany();
130137

131138
const response: GetMatchingsResponse = {
@@ -140,17 +147,19 @@ export class MatchingService {
140147
id: matching.requester.id,
141148
nickname: matching.requester.nickname,
142149
profilePictureUrl: matching.requester.profilePictureUrl,
143-
representativePost: {
144-
postImages: requesterPost.postImages.map((image) => ({
145-
url: image.url,
146-
orderNum: image.orderNum,
147-
})),
148-
styleTags: requesterPost.postStyletags
149-
? requesterPost.postStyletags.map(
150-
(styleTag) => styleTag.styletag.tag,
151-
)
152-
: [],
153-
},
150+
representativePost: requesterPost
151+
? {
152+
postImages: requesterPost.postImages.map((image) => ({
153+
url: image.url,
154+
orderNum: image.orderNum,
155+
})),
156+
styleTags: requesterPost.postStyletags
157+
? requesterPost.postStyletags.map(
158+
(styleTag) => styleTag.styletag.tag,
159+
)
160+
: [],
161+
}
162+
: {},
154163
},
155164
};
156165
}),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class PostClothingService {
5252
// 빈 배열이 들어온 경우
5353
if (uploadClothingDtos.length === 0) {
5454
const clothingsToDeactivate = existingPostClothings.filter(
55-
(existingClothing) => existingClothing.status === 'activated',
55+
(existingClothing) => existingClothing.status === StatusEnum.ACTIVATED,
5656
);
5757

5858
await this.deletePostClothing(clothingsToDeactivate, queryRunner);
@@ -62,7 +62,7 @@ export class PostClothingService {
6262
// 삭제할 PostClothing
6363
const postClothingsToRemove = existingPostClothings.filter(
6464
(existingPostClothing) =>
65-
existingPostClothing.status === 'activated' &&
65+
existingPostClothing.status === StatusEnum.ACTIVATED &&
6666
!uploadClothingDtos.some(
6767
(newClothing) => newClothing.id === existingPostClothing.clothing.id,
6868
),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class PostImageService {
5656
// 삭제할 이미지 목록
5757
const imagesToRemove = existingImages.filter(
5858
(existingImage) =>
59-
existingImage.status === 'activated' &&
59+
existingImage.status === StatusEnum.ACTIVATED &&
6060
!postImages.some((newImage) => newImage.url === existingImage.url),
6161
);
6262

src/post-like/post-like.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ export class PostLikeService {
108108
await this.postLikeRepository.save(likeData);
109109
return {
110110
id: likeData.post.id,
111-
isPostLike: likeData.status === 'activated',
111+
isPostLike: likeData.status === StatusEnum.ACTIVATED,
112112
postLikesCount:
113-
likeData.status === 'activated'
113+
likeData.status === StatusEnum.ACTIVATED
114114
? allLikesData.length + 1
115115
: allLikesData.length - 1,
116116
};
@@ -124,7 +124,7 @@ export class PostLikeService {
124124
await this.postLikeRepository.save(newLike);
125125
return {
126126
id: newLike.post.id,
127-
isPostLike: newLike.status === 'activated',
127+
isPostLike: newLike.status === StatusEnum.ACTIVATED,
128128
postLikesCount: allLikesData.length + 1,
129129
};
130130
}

src/post-styletag/post-styletag.service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export class PostStyletagService {
7171

7272
if (newTags.length === 0) {
7373
const tagsToDelete = existingPostStyletags.filter(
74-
(existingPostStyletag) => existingPostStyletag.status === 'activated',
74+
(existingPostStyletag) =>
75+
existingPostStyletag.status === StatusEnum.ACTIVATED,
7576
);
7677

7778
await this.deletePostStyletags(tagsToDelete, queryRunner);
@@ -88,7 +89,7 @@ export class PostStyletagService {
8889
const newTagIds = styleTags.map((tag) => tag.id);
8990
const tagsToRemove = existingPostStyletags.filter(
9091
(existingTag) =>
91-
existingTag.status === 'activated' &&
92+
existingTag.status === StatusEnum.ACTIVATED &&
9293
!newTagIds.includes(existingTag.styletag.id),
9394
);
9495

src/post/post.service.ts

+20-18
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ export class PostService {
6060
'post.postImages',
6161
'postImage',
6262
'postImage.status = :status',
63-
{ status: 'activated' },
63+
{ status: StatusEnum.ACTIVATED },
6464
)
6565
.leftJoin(
6666
'post.postLikes',
6767
'postLike',
6868
'postLike.status = :status and postLike.postId = post.id and postLike.userId = :currentUserId',
6969
{
70-
status: 'activated',
70+
status: StatusEnum.ACTIVATED,
7171
currentUserId,
7272
},
7373
)
7474
.addSelect(['postLike.id'])
75-
.where('post.status = :status', { status: 'activated' })
76-
.andWhere('user.status = :status', { status: 'activated' })
75+
.where('post.status = :status', { status: StatusEnum.ACTIVATED })
76+
.andWhere('user.status = :status', { status: StatusEnum.ACTIVATED })
7777
.andWhere('user.id NOT IN (:currentUserId)', {
7878
currentUserId: [currentUserId],
7979
})
@@ -121,14 +121,14 @@ export class PostService {
121121
'post.postImages',
122122
'postImage',
123123
'postImage.status = :status AND postImage.orderNum = :orderNum',
124-
{ status: 'activated', orderNum: 1 },
124+
{ status: StatusEnum.ACTIVATED, orderNum: 1 },
125125
)
126126
.leftJoinAndSelect(
127127
'post.postLikes',
128128
'postLike',
129129
'postLike.status = :likeStatus',
130130
{
131-
likeStatus: 'activated',
131+
likeStatus: StatusEnum.ACTIVATED,
132132
},
133133
)
134134
.leftJoinAndSelect('postLike.user', 'postLikeUser')
@@ -137,11 +137,11 @@ export class PostService {
137137
'postComment',
138138
'postComment.status = :commentStatus',
139139
{
140-
commentStatus: 'activated',
140+
commentStatus: StatusEnum.ACTIVATED,
141141
},
142142
)
143143
.leftJoinAndSelect('postComment.user', 'postCommentUser')
144-
.where('post.status = :status', { status: 'activated' })
144+
.where('post.status = :status', { status: StatusEnum.ACTIVATED })
145145
.andWhere('post.user.id = :userId', { userId })
146146
.select([
147147
'post.id',
@@ -317,20 +317,20 @@ export class PostService {
317317
'post.postImages',
318318
'postImage',
319319
'postImage.status = :status',
320-
{ status: 'activated' },
320+
{ status: StatusEnum.ACTIVATED },
321321
)
322322
.leftJoinAndSelect(
323323
'post.postStyletags',
324324
'postStyletag',
325325
'postStyletag.status = :status',
326-
{ status: 'activated' },
326+
{ status: StatusEnum.ACTIVATED },
327327
)
328328
.leftJoinAndSelect('postStyletag.styletag', 'styletag')
329329
.leftJoinAndSelect(
330330
'post.postClothings',
331331
'postClothing',
332332
'postClothing.status = :status',
333-
{ status: 'activated' },
333+
{ status: StatusEnum.ACTIVATED },
334334
)
335335
.leftJoinAndSelect('postClothing.clothing', 'clothing')
336336
.leftJoinAndSelect('post.user', 'user')
@@ -395,15 +395,15 @@ export class PostService {
395395
'post.postImages',
396396
'postImage',
397397
'postImage.status = :imageStatus',
398-
{ imageStatus: 'activated' },
398+
{ imageStatus: StatusEnum.ACTIVATED },
399399
)
400400
.leftJoinAndSelect('post.user', 'user')
401401
.leftJoinAndSelect(
402402
'post.postLikes',
403403
'postLike',
404404
'postLike.status = :likeStatus AND postLike.user.id NOT IN (:...blockedUserIds)',
405405
{
406-
likeStatus: 'activated',
406+
likeStatus: StatusEnum.ACTIVATED,
407407
blockedUserIds: blockedUserIds.length > 0 ? blockedUserIds : [-1], // 차단된 사용자가 없으면 무효화된 조건 (-1)
408408
},
409409
)
@@ -413,7 +413,7 @@ export class PostService {
413413
'postComment',
414414
'postComment.status = :commentStatus AND postComment.user.id NOT IN (:...blockedUserIds)',
415415
{
416-
commentStatus: 'activated',
416+
commentStatus: StatusEnum.ACTIVATED,
417417
blockedUserIds: blockedUserIds.length > 0 ? blockedUserIds : [-1],
418418
},
419419
)
@@ -422,18 +422,20 @@ export class PostService {
422422
'post.postClothings',
423423
'postClothing',
424424
'postClothing.status = :clothingStatus',
425-
{ clothingStatus: 'activated' },
425+
{ clothingStatus: StatusEnum.ACTIVATED },
426426
)
427427
.leftJoinAndSelect('postClothing.clothing', 'clothing')
428428
.leftJoinAndSelect(
429429
'post.postStyletags',
430430
'postStyletag',
431431
'postStyletag.status = :styletagStatus',
432-
{ styletagStatus: 'activated' },
432+
{ styletagStatus: StatusEnum.ACTIVATED },
433433
)
434434
.leftJoinAndSelect('postStyletag.styletag', 'styletag')
435435
.where('post.id = :postId', { postId })
436-
.andWhere('post.status = :postStatus', { postStatus: 'activated' })
436+
.andWhere('post.status = :postStatus', {
437+
postStatus: StatusEnum.ACTIVATED,
438+
})
437439
.getOne();
438440
}
439441

@@ -499,7 +501,7 @@ export class PostService {
499501
{
500502
user: { id: userId },
501503
isRepresentative: true,
502-
status: 'activated',
504+
status: StatusEnum.ACTIVATED,
503505
},
504506
{ isRepresentative: false },
505507
);

src/user/dto/response/user.response.ts

+16
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ export class GetUserInfo {
4848
example: '2000-12-17',
4949
})
5050
birthDate: string;
51+
52+
constructor(user: Partial<GetUserInfo>) {
53+
this.id = user.id;
54+
this.name = user.name;
55+
this.phoneNumber = user.phoneNumber;
56+
this.email = user.email;
57+
this.nickname = user.nickname;
58+
this.profilePictureUrl = user.profilePictureUrl;
59+
this.bio = user.bio;
60+
this.birthDate = user.birthDate;
61+
}
5162
}
5263

5364
export class GetOtherUserInfo extends GetUserInfo {
@@ -56,4 +67,9 @@ export class GetOtherUserInfo extends GetUserInfo {
5667
example: true,
5768
})
5869
isMatching: boolean;
70+
71+
constructor(user: Partial<GetOtherUserInfo>, isMatching: boolean) {
72+
super(user);
73+
this.isMatching = isMatching;
74+
}
5975
}

0 commit comments

Comments
 (0)