diff --git a/services/meetingService.js b/services/meetingService.js index bbc157f4fda44525a28f15d1c13a1ae9211b977e..b529db0609c03d773e2c5ce05e6c88c4d762d73f 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);