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