From c36ad889fc75350aa30d1fe048865e08597400e1 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: Tue, 26 Nov 2024 15:12:02 +0900
Subject: [PATCH] =?UTF-8?q?feat:=20=EB=82=B4=EA=B0=80=20=EC=B0=B8=EC=97=AC?=
 =?UTF-8?q?=ED=95=9C=20=EB=AF=B8=ED=8C=85=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0?=
 =?UTF-8?q?=ED=9A=8C=20(#19)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 services/meetingService.js | 68 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/services/meetingService.js b/services/meetingService.js
index bbc157f..b529db0 100644
--- a/services/meetingService.js
+++ b/services/meetingService.js
@@ -341,6 +341,74 @@ class MeetingService {
         };
     }
 
+    async getMyMeetings(userId, pagination) {
+        const { limit = 20, offset = 0 } = pagination;
+    
+        const meetings = await Meeting.findAll({
+            attributes: [
+                'id',
+                'title',
+                'description',
+                'time_idx_start',
+                'time_idx_end',
+                'location',
+                'time_idx_deadline',
+                'type',
+                'max_num',
+                'cur_num',
+            ],
+            include: [
+                {
+                    model: MeetingParticipant,
+                    as: 'participants',
+                    where: { user_id: userId }, 
+                    attributes: [],
+                },
+                {
+                    model: User,
+                    as: 'creator',
+                    attributes: ['name'],
+                }
+            ],
+            where: {
+                [Op.or]: [
+                    { created_by: userId },  
+                    { '$participants.user_id$': userId }  
+                ]
+            },
+            order: [['createdAt', 'DESC']],
+            offset
+        });
+    
+        const hasNext = meetings.length > limit;
+        const content = await Promise.all(
+            meetings.slice(0, limit).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, !!isParticipant, hasConflict, creatorName);
+            })
+        );
+    
+        return {
+            content,
+            hasNext
+        };
+    }
+
+    
+
   
     async closeMeeting(meetingId) {
         const meeting = await Meeting.findByPk(meetingId);
-- 
GitLab