diff --git a/controllers/inviteController.js b/controllers/inviteController.js index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..16a8796cbcf9027363373f3ce436b3c899ca8ec3 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 4363b41365ea22d274b6cc14526bd1669fc7da09..12ee66a740228e3ee825b171ef6df7a5d1060ccc 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) {