Skip to content
Snippets Groups Projects
Commit 7356196e authored by Wo-ogie's avatar Wo-ogie
Browse files

feat: 참가자 생성 시 약속 최대 참가자 수를 넘어선다면 에러가 발생하도록 예외처리 추가

parent 8ce5b334
Branches
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ const { ...@@ -5,6 +5,7 @@ const {
getMeetingById, getMeetingById,
getMeetingWithParticipantsById, getMeetingWithParticipantsById,
getMeetingWithParticipantsAndSchedulesById, getMeetingWithParticipantsAndSchedulesById,
getNumOfParticipantsByMeetingId,
closeMeetingById, closeMeetingById,
} = require('../services/meeting'); } = require('../services/meeting');
const { const {
...@@ -44,14 +45,6 @@ async function getParticipantByNameAndMeetingId(name, meetingId) { ...@@ -44,14 +45,6 @@ async function getParticipantByNameAndMeetingId(name, meetingId) {
return participant; return participant;
} }
async function getNumOfParticipantsByMeetingId(meetingId) {
return Participant.count({
where: {
MeetingId: meetingId,
},
});
}
async function validatePasswordIsMatched(requestPassword, exPassword) { async function validatePasswordIsMatched(requestPassword, exPassword) {
if (!requestPassword) { if (!requestPassword) {
throw createPasswordIsNullError(); throw createPasswordIsNullError();
......
const bcrypt = require('bcrypt'); const bcrypt = require('bcrypt');
const { createPasswordIsNullError } = require('../errors/meetingErrors'); const {
getMeetingById,
getNumOfParticipantsByMeetingId,
} = require('../services/meeting');
const {
createPasswordIsNullError,
createMaxParticipantsError,
} = require('../errors/meetingErrors');
const { const {
createParticipantIsAlreadyExistError, createParticipantIsAlreadyExistError,
createParticipantNotFoundError, createParticipantNotFoundError,
...@@ -65,6 +72,13 @@ exports.createParticipant = async (req, res, next) => { ...@@ -65,6 +72,13 @@ exports.createParticipant = async (req, res, next) => {
const reqPassword = req.body.password || null; const reqPassword = req.body.password || null;
const reqEmail = req.body.email || null; const reqEmail = req.body.email || null;
try { try {
const meeting = await getMeetingById(meetingId);
const currentParticipants =
await getNumOfParticipantsByMeetingId(meetingId);
if (currentParticipants >= meeting.maxParticipants) {
throw createMaxParticipantsError();
}
const existingParticipant = await findParticipantByMeetingIdAndName( const existingParticipant = await findParticipantByMeetingIdAndName(
meetingId, meetingId,
reqName, reqName,
......
...@@ -29,3 +29,11 @@ exports.createMostConfirmedTimeNotFoundError = () => { ...@@ -29,3 +29,11 @@ exports.createMostConfirmedTimeNotFoundError = () => {
error.status = 404; error.status = 404;
return error; return error;
}; };
exports.createMaxParticipantsError = () => {
const error = new Error(
'설정된 최대 참가자가 모두 참여했습니다. 더 이상 새로 참가하실 수 없습니다.',
);
error.status = 409;
return error;
};
...@@ -50,6 +50,13 @@ const getMeetingWithParticipantsAndSchedulesById = async (meetingId) => { ...@@ -50,6 +50,13 @@ const getMeetingWithParticipantsAndSchedulesById = async (meetingId) => {
return meeting; return meeting;
}; };
const getNumOfParticipantsByMeetingId = async (meetingId) =>
Participant.count({
where: {
MeetingId: meetingId,
},
});
function validateMeetingIsNotClosed(meeting) { function validateMeetingIsNotClosed(meeting) {
if (meeting.isClosed === true) { if (meeting.isClosed === true) {
throw createMeetingIsAlreadyClosedError(); throw createMeetingIsAlreadyClosedError();
...@@ -75,5 +82,6 @@ module.exports = { ...@@ -75,5 +82,6 @@ module.exports = {
getMeetingById, getMeetingById,
getMeetingWithParticipantsById, getMeetingWithParticipantsById,
getMeetingWithParticipantsAndSchedulesById, getMeetingWithParticipantsAndSchedulesById,
getNumOfParticipantsByMeetingId,
closeMeetingById, closeMeetingById,
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment