From d6a423cceab25b730a490039056d12cbdb016fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EB=8C=80=ED=9D=AC?= <joedaehui@ajou.ac.kr> Date: Mon, 25 Nov 2024 20:15:53 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=AF=B8=ED=8C=85=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D/=EC=83=81=EC=84=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=88=98=EC=A0=95=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/meetingService.js | 55 +++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/services/meetingService.js b/services/meetingService.js index d7b6023..653b73a 100644 --- a/services/meetingService.js +++ b/services/meetingService.js @@ -299,21 +299,34 @@ class MeetingService { { model: MeetingParticipant, as: 'participants', - where: { user_id: userId }, // userId와 매핑된 미팅만 가져옴 - attributes: [], + required: false, + attributes: [], }, { model: User, as: 'creator', - attributes: ['name'], // 미팅 생성자의 이름만 필요 - }, - ], + attributes: ['name'], + } + ] }); - - return meetings.map((meeting) => { + + return Promise.all(meetings.map(async (meeting) => { + const isParticipant = await MeetingParticipant.findOne({ + where: { + meeting_id: meeting.id, + user_id: userId + } + }); + + const hasConflict = await ScheduleService.checkScheduleOverlapByTime( + userId, + meeting.time_idx_start, + meeting.time_idx_end + ); + const creatorName = meeting.creator ? meeting.creator.name : 'Unknown'; - return new MeetingResponseDTO(meeting, true, false, creatorName); - }); + return new MeetingResponseDTO(meeting, !!isParticipant, hasConflict, creatorName); + })); } @@ -451,7 +464,7 @@ class MeetingService { - async getMeetingDetail(meetingId) { + async getMeetingDetail(meetingId, userId) { const meeting = await Meeting.findByPk(meetingId, { include: [ { @@ -465,19 +478,25 @@ class MeetingService { include: [ { model: User, - as: "user", // 'participantUser'에서 'user'로 수정 + as: "user", attributes: ["name", "email"], - }, - ], - }, - ], + } + ] + } + ] }); - + if (!meeting) { throw new Error("모임을 찾을 수 없습니다."); } - - return new MeetingDetailResponseDTO(meeting); + + const hasConflict = await ScheduleService.checkScheduleOverlapByTime( + userId, + meeting.time_idx_start, + meeting.time_idx_end + ); + + return new MeetingDetailResponseDTO(meeting, hasConflict); } /** -- GitLab