From a2f2607a16226d1b0fa42f4c4114ec0b7ec5b36b Mon Sep 17 00:00:00 2001 From: tpgus2603 <kakaneymar2424@gmail.com> Date: Wed, 27 Nov 2024 00:42:37 +0900 Subject: [PATCH] =?UTF-8?q?feature=20=EB=B3=80=EA=B2=BD=EC=82=AC=ED=95=AD?= =?UTF-8?q?=20=EA=B8=B0=EB=A1=9D(#15)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/inviteController.js | 67 ++++++++++++++++++++++++++++++++ controllers/meetingController.js | 1 + 2 files changed, 68 insertions(+) diff --git a/controllers/inviteController.js b/controllers/inviteController.js index e69de29..16a8796 100644 --- a/controllers/inviteController.js +++ b/controllers/inviteController.js @@ -0,0 +1,67 @@ +// controllers/inviteController.js +const { Invite, Meeting, User, MeetingParticipant } = require('../models'); +const MeetingService = require('../services/meetingService'); + +/** + * 초대에 응답하는 메서드 + * @param {number} inviteId - 응답할 초대의 ID + * @param {number} userId - 응답하는 사용자의 ID + * @param {string} response - 응답 (ACCEPTED, DECLINED) + * @returns {Object} 응답 결과 + */ +async function respondToInvite(inviteId, userId, response) { + // 초대 조회 + const invite = await Invite.findOne({ + where: { + id: inviteId, + invitee_id: userId, + }, + include: [ + { model: Meeting, as: 'meeting' }, + { model: User, as: 'inviter' } + ] + }); + + if (!invite) { + throw new Error('초대를 찾을 수 없습니다.'); + } + + if (!['ACCEPTED', 'DECLINED'].includes(response)) { + throw new Error('유효하지 않은 응답입니다.'); + } + + if (response === 'ACCEPTED') { + // 초대 수락 시, MeetingService의 joinMeeting 메서드 호출 + await MeetingService.joinMeeting(invite.meeting_id, userId); + } + + // 초대를 삭제 + await invite.destroy(); + + return { inviteId, response }; +} + +/** + * 사용자가 받은 초대 목록을 조회하는 메서드 + * @param {number} userId - 초대를 받은 사용자의 ID + * @returns {Array} 초대 목록 + */ +async function getReceivedInvites(userId) { + const invites = await Invite.findAll({ + where: { + invitee_id: userId, + status: 'PENDING', + }, + include: [ + { model: Meeting, as: 'meeting' }, + { model: User, as: 'inviter', attributes: ['id', 'name', 'email'] }, + ], + }); + + return invites; +} + +module.exports = { + respondToInvite, + getReceivedInvites, +}; diff --git a/controllers/meetingController.js b/controllers/meetingController.js index d85e788..bffc946 100644 --- a/controllers/meetingController.js +++ b/controllers/meetingController.js @@ -16,6 +16,7 @@ class MeetingController { * "location": "회의실 A", * "deadline": "2024-04-25T23:59:59Z", * "type": "OPEN" // "OPEN" 또는 "CLOSE" + * "max_num": * } */ async createMeeting(req, res) { -- GitLab