Commit f8a30995 authored by Soo Hyun Kim's avatar Soo Hyun Kim
Browse files

0120참여코드로참가

parent a176c47f
...@@ -7,6 +7,9 @@ import catchErrors from '../utils/catchErrors' ...@@ -7,6 +7,9 @@ import catchErrors from '../utils/catchErrors'
function EnterRoom(props) { function EnterRoom(props) {
const [enterCode, setEnterCode] = useState(''); const [enterCode, setEnterCode] = useState('');
const [error, setError] = useState(''); const [error, setError] = useState('');
const userId = sessionStorage.getItem('userId'); //sessionStorage에 저장된 userId가져옴
function handleChange(event) { function handleChange(event) {
const { name, value } = event.target const { name, value } = event.target
...@@ -19,6 +22,7 @@ function EnterRoom(props) { ...@@ -19,6 +22,7 @@ function EnterRoom(props) {
try { try {
setError('') setError('')
let res = await axios.post('/room/enterRoom', { enterCode }) let res = await axios.post('/room/enterRoom', { enterCode })
await axios.put('/room/member', { userId: userId, roomId: enterCode })
props.setRoomName(res.data) props.setRoomName(res.data)
props.enterChatRoom(enterCode) props.enterChatRoom(enterCode)
props.handleCloseEnter() props.handleCloseEnter()
......
...@@ -41,7 +41,7 @@ const getClosedList = async (req, res) => { ...@@ -41,7 +41,7 @@ const getClosedList = async (req, res) => {
try { try {
console.log('req확인',req.query._id) console.log('req확인',req.query._id)
let list = await Room.find({ member: [req.query._id] }) let list = await Room.find({ member: [req.query._id] })
console.log('c_list가져오기', list) console.log('c_list가져오기', list.roomName)
return res.json(list) return res.json(list)
} catch (error) { } catch (error) {
res.status(500).send('리스트 불러오기를 실패하였습니다!') res.status(500).send('리스트 불러오기를 실패하였습니다!')
...@@ -51,11 +51,29 @@ const getClosedList = async (req, res) => { ...@@ -51,11 +51,29 @@ const getClosedList = async (req, res) => {
const getOpenList = async (req, res) => { const getOpenList = async (req, res) => {
try { try {
let list = await Room.find({ isOpen: true }) let list = await Room.find({ isOpen: true })
console.log('o_list가져오기', list) console.log('o_list가져오기', list.roomName)
return res.json(list) return res.json(list)
} catch (error) { } catch (error) {
res.status(500).send('리스트 불러오기를 실패하였습니다!') res.status(500).send('리스트 불러오기를 실패하였습니다!')
} }
} }
export default { makeRoom, getClosedList, getOpenList } const changemember = async (req, res) => {
const { userId, roomId } = req.body
console.log(roomId)
let room = await Room.findOne({ roomId: roomId }).select('member')
const isPresent = room.member.indexOf(userId)
try {
if (isPresent<0) {
const memberId = room.member.push(userId)
await Room.updateOne({ 'roomId': roomId }, { 'member': room.member })
console.log('room.member 업데이트 완료')
}
res.end()
} catch (error) {
console.log(error)
res.status(500).send('멤버 업데이트 실패')
}
}
export default { makeRoom, getClosedList, getOpenList, changemember }
...@@ -5,7 +5,6 @@ const roomEnter = async (req, res) => { ...@@ -5,7 +5,6 @@ const roomEnter = async (req, res) => {
// console.log(req) // console.log(req)
try { try {
console.log(roomId)
const room = await Room.findOne({ roomId }) const room = await Room.findOne({ roomId })
if (!room) { if (!room) {
return res.status(404).send(`참여코드가 존재하지 않습니다.`) return res.status(404).send(`참여코드가 존재하지 않습니다.`)
......
...@@ -11,4 +11,7 @@ router.route('/room/closedlist') ...@@ -11,4 +11,7 @@ router.route('/room/closedlist')
router.route('/room/openlist') router.route('/room/openlist')
.get(roomCtrl.getOpenList) .get(roomCtrl.getOpenList)
router.route('/room/member')
.put(roomCtrl.changemember)
export default router export default router
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment