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

refactor: 약속 입장 시, 존재하지 않는 참가자로 입장하려고 하면 404 error를 발생시키도록 수정

parent b09087dc
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,9 @@ const {
} = require('../errors/meetingErrors');
const MeetingResponse = require('../dto/response/meetingResponse');
const MeetingWithParticipantsResponse = require('../dto/response/meetingWithParticipantsResponse');
const ParticipantResponse = require('../dto/response/participantResponse');
const {
createParticipantNotFoundError,
} = require('../errors/participantErrors');
const HASHING_ROUND = 12;
......@@ -54,6 +56,19 @@ async function getMeetingWithParticipantsAndSchedulesById(meetingId) {
return meeting;
}
async function getParticipantByNameAndMeetingId(name, meetingId) {
const participant = await Participant.findOne({
where: {
name,
MeetingId: meetingId,
},
});
if (!participant) {
throw createParticipantNotFoundError();
}
return participant;
}
async function validatePasswordIsMatched(requestPassword, exPassword) {
if (!requestPassword) {
throw createPasswordIsNullError();
......@@ -115,32 +130,20 @@ exports.createMeeting = async (req, res, next) => {
};
exports.entry = async (req, res, next) => {
const meetingIdToEntry = req.params.meetingId;
const nameToEntry = req.body.name;
const passwordToEntry = req.body.password;
const { meetingId } = req.params;
const participantName = req.body.name;
const participantPassword = req.body.password;
try {
const participant = await Participant.findOne({
where: {
name: nameToEntry,
MeetingId: meetingIdToEntry,
},
});
console.log('participant', participant);
if (!participant) {
const passwordEncrypted = await encryptPassword(passwordToEntry, next);
const participantCreated = await Participant.create({
name: nameToEntry,
password: passwordEncrypted,
email: req.body.email,
MeetingId: meetingIdToEntry,
});
setParticipantDataToCookie(req, res, participantCreated);
return res.status(201).json(ParticipantResponse.from(participantCreated));
}
const participant = await getParticipantByNameAndMeetingId(
participantName,
meetingId,
);
if (participant.password) {
await validatePasswordIsMatched(passwordToEntry, participant.password);
await validatePasswordIsMatched(
participantPassword,
participant.password,
);
}
setParticipantDataToCookie(req, res, participant);
return res.status(204).end();
......@@ -169,11 +172,11 @@ exports.getMeetingDetailById = async (req, res, next) => {
}
};
const validateMeetingIsNotClosed = (meeting) => {
function validateMeetingIsNotClosed(meeting) {
if (meeting.isClosed === true) {
throw createMeetingIsAlreadyClosedError();
}
};
}
exports.closeMeeting = async (req, res, next) => {
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment