diff --git a/controllers/meeting.js b/controllers/meeting.js index 0ab9479914e7be561c4692ded83311f50ba0438b..1b3a1f053c5f0d33cd6ab9f5924f332ac6149895 100644 --- a/controllers/meeting.js +++ b/controllers/meeting.js @@ -6,7 +6,6 @@ const { createMeetingIsAlreadyClosedError, createPasswordNotMatchedError, createPasswordIsNullError, - createMostConfirmedTimeNotFoundError, } = require('../errors/meetingErrors'); const MeetingResponse = require('../dto/response/meetingResponse'); const MeetingWithParticipantsResponse = require('../dto/response/meetingWithParticipantsResponse'); @@ -71,6 +70,14 @@ async function getParticipantByNameAndMeetingId(name, meetingId) { return participant; } +async function getNumOfParticipantsByMeetingId(meetingId) { + return Participant.count({ + where: { + MeetingId: meetingId, + }, + }); +} + async function validatePasswordIsMatched(requestPassword, exPassword) { if (!requestPassword) { throw createPasswordIsNullError(); @@ -160,7 +167,13 @@ exports.entry = async (req, res, next) => { exports.getMeetingById = async (req, res, next) => { try { const meeting = await getMeetingById(req.params.meetingId); - return res.json(MeetingResponse.from(meeting)); + const currentParticipants = await getNumOfParticipantsByMeetingId( + meeting.id, + ); + return res.json({ + ...MeetingResponse.from(meeting), + currentParticipants, + }); } catch (error) { return next(error); } @@ -171,7 +184,13 @@ exports.getMeetingDetailById = async (req, res, next) => { const meeting = await getMeetingWithParticipantsAndSchedulesById( req.params.meetingId, ); - return res.json(MeetingWithParticipantsResponse.from(meeting)); + const currentParticipants = await getNumOfParticipantsByMeetingId( + meeting.id, + ); + return res.json({ + ...MeetingWithParticipantsResponse.from(meeting), + currentParticipants, + }); } catch (error) { return next(error); }