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

feat: id, 이름으로 참가자 단건 조회하기 API 구현

parent a1666477
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ const bcrypt = require('bcrypt'); ...@@ -2,6 +2,7 @@ const bcrypt = require('bcrypt');
const { createPasswordIsNullError } = require('../errors/meetingErrors'); const { createPasswordIsNullError } = require('../errors/meetingErrors');
const { const {
createParticipantIsAlreadyExistError, createParticipantIsAlreadyExistError,
createParticipantNotFoundError,
} = require('../errors/participantErrors'); } = require('../errors/participantErrors');
const ParticipantResponse = require('../dto/response/participantResponse'); const ParticipantResponse = require('../dto/response/participantResponse');
const { Participant } = require('../models'); const { Participant } = require('../models');
...@@ -17,6 +18,18 @@ async function createParticipant(name, password, email, meetingId) { ...@@ -17,6 +18,18 @@ async function createParticipant(name, password, email, meetingId) {
}); });
} }
async function getParticipantById(participantId) {
const participant = await Participant.findOne({
where: {
id: participantId,
},
});
if (!participant) {
throw createParticipantNotFoundError();
}
return participant;
}
async function findParticipantByMeetingIdAndName(meetingId, name) { async function findParticipantByMeetingIdAndName(meetingId, name) {
return Participant.findOne({ return Participant.findOne({
where: { where: {
...@@ -26,6 +39,14 @@ async function findParticipantByMeetingIdAndName(meetingId, name) { ...@@ -26,6 +39,14 @@ async function findParticipantByMeetingIdAndName(meetingId, name) {
}); });
} }
async function getParticipantByMeetingIdAndName(meetingId, name) {
const participant = await findParticipantByMeetingIdAndName(meetingId, name);
if (!participant) {
throw createParticipantNotFoundError();
}
return participant;
}
async function encryptPassword(password, next) { async function encryptPassword(password, next) {
if (!password) { if (!password) {
return next(createPasswordIsNullError()); return next(createPasswordIsNullError());
...@@ -69,6 +90,27 @@ exports.createParticipant = async (req, res, next) => { ...@@ -69,6 +90,27 @@ exports.createParticipant = async (req, res, next) => {
} }
}; };
exports.getParticipantById = async (req, res, next) => {
try {
const participant = await getParticipantById(req.params.participantId);
return res.json(ParticipantResponse.from(participant));
} catch (error) {
return next(error);
}
};
exports.getParticipantByName = async (req, res, next) => {
try {
const participant = await getParticipantByMeetingIdAndName(
req.params.meetingId,
req.query.name,
);
return res.json(ParticipantResponse.from(participant));
} catch (error) {
return next(error);
}
};
exports.getParticipantExistence = async (req, res, next) => { exports.getParticipantExistence = async (req, res, next) => {
try { try {
const participant = await findParticipantByMeetingIdAndName( const participant = await findParticipantByMeetingIdAndName(
......
...@@ -5,3 +5,9 @@ exports.createParticipantIsAlreadyExistError = () => { ...@@ -5,3 +5,9 @@ exports.createParticipantIsAlreadyExistError = () => {
error.status = 409; error.status = 409;
return error; return error;
}; };
exports.createParticipantNotFoundError = () => {
const error = new Error('참가자 정보를 찾을 수 없습니다.');
error.status = 404;
return error;
};
const express = require('express'); const express = require('express');
const { const {
createParticipant, createParticipant,
getParticipantByName,
getParticipantById,
getParticipantExistence, getParticipantExistence,
} = require('../controllers/participant'); } = require('../controllers/participant');
...@@ -8,6 +10,10 @@ const router = express.Router(); ...@@ -8,6 +10,10 @@ const router = express.Router();
router.post('/:meetingId/participants', createParticipant); router.post('/:meetingId/participants', createParticipant);
router.get('/:meetingId/participants', getParticipantByName);
router.get('/:meetingId/participants/:participantId', getParticipantById);
router.get('/:meetingId/participants/existence', getParticipantExistence); router.get('/:meetingId/participants/existence', getParticipantExistence);
module.exports = router; module.exports = router;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment