From 042878a90cc8c1d4cc84ed0414f55c352d0b39a1 Mon Sep 17 00:00:00 2001 From: Wo-ogie <siwall0105@gmail.com> Date: Mon, 27 Nov 2023 15:17:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=95=BD=EC=86=8D=20=EC=9E=85?= =?UTF-8?q?=EC=9E=A5=20=EC=8B=9C,=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80?= =?UTF-8?q?=20=EC=95=8A=EB=8A=94=20=EC=B0=B8=EA=B0=80=EC=9E=90=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=85=EC=9E=A5=ED=95=98=EB=A0=A4=EA=B3=A0=20=ED=95=98?= =?UTF-8?q?=EB=A9=B4=20404=20error=EB=A5=BC=20=EB=B0=9C=EC=83=9D=EC=8B=9C?= =?UTF-8?q?=ED=82=A4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/meeting.js | 55 ++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/controllers/meeting.js b/controllers/meeting.js index 30f1667..28d5eda 100644 --- a/controllers/meeting.js +++ b/controllers/meeting.js @@ -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 { -- GitLab