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

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

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