Skip to content

Commit ea7a507

Browse files
authored
Merge pull request #64 from oodd-team/OD-162
매칭 신청 수정 OD-162
2 parents 4a611ad + bb06976 commit ea7a507

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

src/matching/matching.controller.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ export class MatchingController {
7878
}
7979

8080
if (
81-
await this.matchingService.getMatchingByUserId(
82-
body.requesterId,
83-
body.targetId,
84-
)
81+
await this.matchingService.existsMatching(body.requesterId, body.targetId)
8582
)
8683
throw InvalidInputValueException('이미 매칭 요청을 보냈습니다.');
8784

src/matching/matching.service.ts

+31-23
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@ export class MatchingService {
2323
private readonly chatMessageService: ChatMessageService,
2424
private readonly dataSource: DataSource,
2525
) {}
26-
async getMatchingByUserId(
27-
requesterId: number,
28-
targetId: number,
29-
): Promise<Matching> {
30-
return await this.matchingRepository.findOne({
31-
where: [
32-
{
33-
requester: { id: requesterId },
34-
target: { id: targetId },
35-
status: StatusEnum.ACTIVATED,
36-
},
37-
{
38-
requester: { id: targetId },
39-
target: { id: requesterId },
40-
status: StatusEnum.ACTIVATED,
41-
},
42-
],
43-
});
44-
}
4526

4627
async getMatchingsByCurrentId(currentUserId: number): Promise<Matching[]> {
4728
return await this.matchingRepository.find({
@@ -61,6 +42,7 @@ export class MatchingService {
6142
const matching = await queryRunner.manager.save(Matching, {
6243
requester: { id: body.requesterId },
6344
target: { id: body.targetId },
45+
message: body.message,
6446
});
6547

6648
const chatRoom = await this.chatRoomService.createChatRoom(
@@ -179,10 +161,7 @@ export class MatchingService {
179161
});
180162
}
181163

182-
async existsMatching(
183-
requesterId: number,
184-
targetId: number,
185-
): Promise<boolean> {
164+
async isMatching(requesterId: number, targetId: number): Promise<boolean> {
186165
const count = await this.matchingRepository.count({
187166
where: [
188167
{
@@ -202,4 +181,33 @@ export class MatchingService {
202181

203182
return count > 0;
204183
}
184+
185+
async existsMatching(
186+
requesterId: number,
187+
targetId: number,
188+
): Promise<boolean> {
189+
const matching = await this.matchingRepository.findOne({
190+
where: [
191+
{
192+
requester: { id: requesterId },
193+
target: { id: targetId },
194+
status: StatusEnum.ACTIVATED,
195+
},
196+
{
197+
requester: { id: targetId },
198+
target: { id: requesterId },
199+
status: StatusEnum.ACTIVATED,
200+
},
201+
],
202+
});
203+
204+
// 매칭이 없거나 REJECTED 상태이면 false
205+
if (
206+
!matching ||
207+
matching.requestStatus === MatchingRequestStatusEnum.REJECTED
208+
) {
209+
return false;
210+
}
211+
return true;
212+
}
205213
}

src/user/user.controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class UserController {
5252
const currentUserId = req.user.id; // 또는 다른 방법으로 현재 사용자 ID를 가져옴
5353

5454
// MatchingService를 통해 해당 사용자가 친구인지 확인
55-
const isFriend = await this.matchingService.existsMatching(
55+
const isFriend = await this.matchingService.isMatching(
5656
currentUserId,
5757
userId,
5858
);

0 commit comments

Comments
 (0)