Skip to content

Commit 4a611ad

Browse files
authored
Merge pull request #63 from oodd-team/OD-50
매칭 서비스 ENUM 수정
2 parents b1ae5d2 + 85f48db commit 4a611ad

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/matching/matching.controller.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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';
4141
import { StatusEnum } from 'src/common/enum/entityStatus';
42+
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
4243

4344
@ApiBearerAuth('Authorization')
4445
@Controller('matching')
@@ -104,14 +105,15 @@ export class MatchingController {
104105
const chatRoom = await this.chatRoomService.getChatRoomByMatchingId(
105106
matching.id,
106107
);
108+
if (!matching) {
109+
throw DataNotFoundException('해당 매칭 요청을 찾을 수 없습니다.');
110+
}
107111
if (req.user.id !== matching.target.id) {
108112
throw UnauthorizedException('권한이 없습니다.');
109113
}
110-
111-
if (matching.requestStatus !== 'pending') {
114+
if (matching.requestStatus !== MatchingRequestStatusEnum.PENDING) {
112115
throw InvalidInputValueException('이미 처리된 요청입니다.');
113116
}
114-
115117
if (!chatRoom) {
116118
throw DataNotFoundException('채팅방을 찾을 수 없습니다.');
117119
}

src/matching/matching.service.ts

+10-16
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import {
66
import { DataSource, Repository } from 'typeorm';
77
import { Matching } from 'src/common/entities/matching.entity';
88
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';
1310
import { ChatMessageService } from 'src/chat-message/chat-message.service';
1411
import { ChatRoom } from 'src/common/entities/chat-room.entity';
1512
import { InjectRepository } from '@nestjs/typeorm';
@@ -57,17 +54,16 @@ export class MatchingService {
5754
}
5855

5956
async createMatching(body: CreateMatchingReqeust): Promise<ChatRoom> {
60-
let matching, chatRoom;
6157
const queryRunner = this.dataSource.createQueryRunner();
6258
await queryRunner.connect();
6359
await queryRunner.startTransaction();
6460
try {
65-
matching = await queryRunner.manager.save(Matching, {
61+
const matching = await queryRunner.manager.save(Matching, {
6662
requester: { id: body.requesterId },
6763
target: { id: body.targetId },
6864
});
6965

70-
chatRoom = await this.chatRoomService.createChatRoom(
66+
const chatRoom = await this.chatRoomService.createChatRoom(
7167
queryRunner,
7268
matching,
7369
body,
@@ -105,7 +101,7 @@ export class MatchingService {
105101
const chatRoom = await this.chatRoomService.getChatRoomByMatchingId(
106102
matching.id,
107103
);
108-
chatRoom.requestStatus = 'accepted';
104+
chatRoom.requestStatus = MatchingRequestStatusEnum.ACCEPTED;
109105
await queryRunner.manager.save(chatRoom);
110106
} else if (body.requestStatus === 'reject') {
111107
matching.requestStatus = MatchingRequestStatusEnum.REJECTED;
@@ -133,7 +129,9 @@ export class MatchingService {
133129
.leftJoinAndSelect('post.postStyletags', 'styleTag')
134130
.leftJoinAndSelect('styleTag.styletag', 'styletag')
135131
.where('matching.targetId = :currentUserId', { currentUserId })
136-
.andWhere('matching.requestStatus = :status', { status: 'pending' })
132+
.andWhere('matching.requestStatus = :status', {
133+
status: MatchingRequestStatusEnum.PENDING,
134+
})
137135
.andWhere('matching.status = :activated', { activated: 'activated' })
138136
.orderBy(
139137
// 우선순위: isRepresentative가 true인 게시물 먼저, 그 다음은 최신 게시물
@@ -175,21 +173,17 @@ export class MatchingService {
175173
}
176174

177175
async getMatchingById(matchingId: number): Promise<Matching> {
178-
const matching = await this.matchingRepository.findOne({
176+
return await this.matchingRepository.findOne({
179177
where: { id: matchingId },
180178
relations: ['target', 'requester'],
181179
});
182-
if (!matching) {
183-
throw DataNotFoundException('해당 매칭 요청을 찾을 수 없습니다.');
184-
}
185-
return matching;
186180
}
187181

188182
async existsMatching(
189183
requesterId: number,
190184
targetId: number,
191185
): Promise<boolean> {
192-
const matching = await this.matchingRepository.findOne({
186+
const count = await this.matchingRepository.count({
193187
where: [
194188
{
195189
requester: { id: requesterId },
@@ -206,6 +200,6 @@ export class MatchingService {
206200
],
207201
});
208202

209-
return !!matching; // 매칭 데이터가 있으면 true 반환
203+
return count > 0;
210204
}
211205
}

0 commit comments

Comments
 (0)