@@ -6,10 +6,7 @@ import {
6
6
import { DataSource , Repository } from 'typeorm' ;
7
7
import { Matching } from 'src/common/entities/matching.entity' ;
8
8
import { ChatRoomService } from '../chat-room/chat-room.service' ;
9
- import {
10
- DataNotFoundException ,
11
- InternalServerException ,
12
- } from 'src/common/exception/service.exception' ;
9
+ import { InternalServerException } from 'src/common/exception/service.exception' ;
13
10
import { ChatMessageService } from 'src/chat-message/chat-message.service' ;
14
11
import { ChatRoom } from 'src/common/entities/chat-room.entity' ;
15
12
import { InjectRepository } from '@nestjs/typeorm' ;
@@ -57,17 +54,16 @@ export class MatchingService {
57
54
}
58
55
59
56
async createMatching ( body : CreateMatchingReqeust ) : Promise < ChatRoom > {
60
- let matching , chatRoom ;
61
57
const queryRunner = this . dataSource . createQueryRunner ( ) ;
62
58
await queryRunner . connect ( ) ;
63
59
await queryRunner . startTransaction ( ) ;
64
60
try {
65
- matching = await queryRunner . manager . save ( Matching , {
61
+ const matching = await queryRunner . manager . save ( Matching , {
66
62
requester : { id : body . requesterId } ,
67
63
target : { id : body . targetId } ,
68
64
} ) ;
69
65
70
- chatRoom = await this . chatRoomService . createChatRoom (
66
+ const chatRoom = await this . chatRoomService . createChatRoom (
71
67
queryRunner ,
72
68
matching ,
73
69
body ,
@@ -105,7 +101,7 @@ export class MatchingService {
105
101
const chatRoom = await this . chatRoomService . getChatRoomByMatchingId (
106
102
matching . id ,
107
103
) ;
108
- chatRoom . requestStatus = 'accepted' ;
104
+ chatRoom . requestStatus = MatchingRequestStatusEnum . ACCEPTED ;
109
105
await queryRunner . manager . save ( chatRoom ) ;
110
106
} else if ( body . requestStatus === 'reject' ) {
111
107
matching . requestStatus = MatchingRequestStatusEnum . REJECTED ;
@@ -133,7 +129,9 @@ export class MatchingService {
133
129
. leftJoinAndSelect ( 'post.postStyletags' , 'styleTag' )
134
130
. leftJoinAndSelect ( 'styleTag.styletag' , 'styletag' )
135
131
. where ( 'matching.targetId = :currentUserId' , { currentUserId } )
136
- . andWhere ( 'matching.requestStatus = :status' , { status : 'pending' } )
132
+ . andWhere ( 'matching.requestStatus = :status' , {
133
+ status : MatchingRequestStatusEnum . PENDING ,
134
+ } )
137
135
. andWhere ( 'matching.status = :activated' , { activated : 'activated' } )
138
136
. orderBy (
139
137
// 우선순위: isRepresentative가 true인 게시물 먼저, 그 다음은 최신 게시물
@@ -175,21 +173,17 @@ export class MatchingService {
175
173
}
176
174
177
175
async getMatchingById ( matchingId : number ) : Promise < Matching > {
178
- const matching = await this . matchingRepository . findOne ( {
176
+ return await this . matchingRepository . findOne ( {
179
177
where : { id : matchingId } ,
180
178
relations : [ 'target' , 'requester' ] ,
181
179
} ) ;
182
- if ( ! matching ) {
183
- throw DataNotFoundException ( '해당 매칭 요청을 찾을 수 없습니다.' ) ;
184
- }
185
- return matching ;
186
180
}
187
181
188
182
async existsMatching (
189
183
requesterId : number ,
190
184
targetId : number ,
191
185
) : Promise < boolean > {
192
- const matching = await this . matchingRepository . findOne ( {
186
+ const count = await this . matchingRepository . count ( {
193
187
where : [
194
188
{
195
189
requester : { id : requesterId } ,
@@ -206,6 +200,6 @@ export class MatchingService {
206
200
] ,
207
201
} ) ;
208
202
209
- return ! ! matching ; // 매칭 데이터가 있으면 true 반환
203
+ return count > 0 ;
210
204
}
211
205
}
0 commit comments