Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
f8a30995
Commit
f8a30995
authored
Jan 20, 2021
by
Soo Hyun Kim
Browse files
0120참여코드로참가
parent
a176c47f
Changes
4
Show whitespace changes
Inline
Side-by-side
client/src/Components/EnterRoom.js
View file @
f8a30995
...
...
@@ -8,6 +8,9 @@ function EnterRoom(props) {
const
[
enterCode
,
setEnterCode
]
=
useState
(
''
);
const
[
error
,
setError
]
=
useState
(
''
);
const
userId
=
sessionStorage
.
getItem
(
'
userId
'
);
//sessionStorage에 저장된 userId가져옴
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
setEnterCode
(
value
)
...
...
@@ -19,6 +22,7 @@ function EnterRoom(props) {
try
{
setError
(
''
)
let
res
=
await
axios
.
post
(
'
/room/enterRoom
'
,
{
enterCode
})
await
axios
.
put
(
'
/room/member
'
,
{
userId
:
userId
,
roomId
:
enterCode
})
props
.
setRoomName
(
res
.
data
)
props
.
enterChatRoom
(
enterCode
)
props
.
handleCloseEnter
()
...
...
server/controllers/room.controller.js
View file @
f8a30995
...
...
@@ -41,7 +41,7 @@ const getClosedList = async (req, res) => {
try
{
console
.
log
(
'
req확인
'
,
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
)
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
리스트 불러오기를 실패하였습니다!
'
)
...
...
@@ -51,11 +51,29 @@ const getClosedList = async (req, res) => {
const
getOpenList
=
async
(
req
,
res
)
=>
{
try
{
let
list
=
await
Room
.
find
({
isOpen
:
true
})
console
.
log
(
'
o_list가져오기
'
,
list
)
console
.
log
(
'
o_list가져오기
'
,
list
.
roomName
)
return
res
.
json
(
list
)
}
catch
(
error
)
{
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
}
server/controllers/roomEnter.controller.js
View file @
f8a30995
...
...
@@ -5,7 +5,6 @@ const roomEnter = async (req, res) => {
// console.log(req)
try
{
console
.
log
(
roomId
)
const
room
=
await
Room
.
findOne
({
roomId
})
if
(
!
room
)
{
return
res
.
status
(
404
).
send
(
`참여코드가 존재하지 않습니다.`
)
...
...
server/routes/room.routers.js
View file @
f8a30995
...
...
@@ -11,4 +11,7 @@ router.route('/room/closedlist')
router
.
route
(
'
/room/openlist
'
)
.
get
(
roomCtrl
.
getOpenList
)
router
.
route
(
'
/room/member
'
)
.
put
(
roomCtrl
.
changemember
)
export
default
router
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment