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
bora-it
Commits
0560f339
Commit
0560f339
authored
Jul 27, 2021
by
우지원
Browse files
방참여까지 완료
parent
dd642a51
Changes
5
Hide whitespace changes
Inline
Side-by-side
client/src/components/Home/HomeProfile.js
View file @
0560f339
...
@@ -16,7 +16,7 @@ const HomeProfile = () => {
...
@@ -16,7 +16,7 @@ const HomeProfile = () => {
async
function
getUser
(
id
)
{
async
function
getUser
(
id
)
{
try
{
try
{
// `/users/${userId}`랑 userId랑 같은지 확인
// `/users/${userId}`랑 userId랑 같은지 확인
const
User
=
await
userApi
.
u
ser
(
id
)
const
User
=
await
userApi
.
getU
ser
(
id
)
console
.
log
(
User
)
console
.
log
(
User
)
setUser
(
User
.
data
)
setUser
(
User
.
data
)
console
.
log
(
user
)
console
.
log
(
user
)
...
...
client/src/components/Home/RoomSingle.js
View file @
0560f339
import
{
useEffect
,
useState
}
from
'
react
'
;
import
{
Link
}
from
'
react-router-dom
'
import
{
Link
}
from
'
react-router-dom
'
import
userApi
from
'
../../apis/user.api
'
;
const
RoomSingle
=
()
=>
{
const
RoomSingle
=
()
=>
{
const
id
=
1
const
[
room
,
setRoom
]
=
useState
(
''
)
const
id
=
localStorage
.
getItem
(
'
user
'
);
const
channelId
=
1
const
channelId
=
1
async
function
getRoom
(
id
)
{
try
{
const
Room
=
await
userApi
.
getUser
(
id
)
setRoom
(
Room
.
data
.
roomNumber
)
}
catch
(
error
)
{
// catchErrors(error, setError)
}
}
useEffect
(()
=>
{
getRoom
(
id
)
},
[
id
])
return
(
return
(
<
Link
<
Link
to
=
{
`/room/
${
id
}
/
${
channelId
}
`
}
to
=
{
`/room/
${
id
}
/
${
channelId
}
`
}
...
@@ -33,45 +51,6 @@ const RoomSingle = () => {
...
@@ -33,45 +51,6 @@ const RoomSingle = () => {
<
div
className
=
"
ms-auto mt-2
"
>
15
/
34
<
/div
>
<
div
className
=
"
ms-auto mt-2
"
>
15
/
34
<
/div
>
<
/div
>
<
/div
>
<
div
className
=
"
d-flex mx-4 my-2 p-2
"
style
=
{{
backgroundColor
:
'
#C4C4C4
'
}}
>
<
div
style
=
{{
width
:
'
37px
'
,
height
:
'
37px
'
}}
>
<
img
src
=
"
BORA.png
"
className
=
"
rounded-circle
"
style
=
{{
width
:
'
37px
'
,
height
:
'
37px
'
}}
/
>
<
/div
>
<
div
className
=
"
mx-3 mt-2
"
style
=
{{
width
:
'
250px
'
,
overflow
:
'
scroll
'
,
whiteSpace
:
'
nowrap
'
}}
>
데계
재미있는
수학과
데계데계데계
재미있는
수학과
<
/div
>
<
div
className
=
"
ms-auto mt-2
"
>
15
/
34
<
/div
>
<
/div
>
<
div
className
=
"
d-flex mx-4 my-2 p-2
"
style
=
{{
backgroundColor
:
'
#C4C4C4
'
}}
>
<
div
style
=
{{
width
:
'
37px
'
,
height
:
'
37px
'
}}
>
<
img
src
=
"
BORA.png
"
className
=
"
rounded-circle
"
style
=
{{
width
:
'
37px
'
,
height
:
'
37px
'
}}
/
>
<
/div
>
<
div
className
=
"
mx-3 mt-2
"
style
=
{{
width
:
'
250px
'
,
overflow
:
'
scroll
'
,
whiteSpace
:
'
nowrap
'
}}
>
데계
재미있는
수학과
데계데계데계
재미있는
수학과
<
/div
>
<
div
className
=
"
ms-auto mt-2
"
>
15
/
34
<
/div
>
<
/div
>
<
/Link
>
<
/Link
>
)
)
}
}
...
...
controllers/room.controller.js
View file @
0560f339
import
{
Room
,
User
}
from
"
../models/index.js
"
;
import
{
Room
,
User
}
from
"
../models/index.js
"
;
import
{
customAlphabet
}
from
'
nanoid
'
import
{
customAlphabet
}
from
'
nanoid
'
import
{
Op
}
from
'
sequelize
'
;
import
config
from
"
../config/app.config.js
"
;
import
isLength
from
'
validator/lib/isLength.js
'
import
isLength
from
'
validator/lib/isLength.js
'
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
...
@@ -10,43 +8,39 @@ const joinRoom = async (req, res) => {
...
@@ -10,43 +8,39 @@ const joinRoom = async (req, res) => {
console
.
log
(
'
req.body.value:
'
,
req
.
body
)
console
.
log
(
'
req.body.value:
'
,
req
.
body
)
const
{
userId
,
roomId
}
=
req
.
body
const
{
userId
,
roomId
}
=
req
.
body
const
room_Id
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
const
room_Id
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
console
.
log
(
'
room_Id1:
'
,
room_Id
)
//
console.log('room_Id1:', room_Id)
console
.
log
(
'
room_Id있는지:
'
,
Boolean
(
room_Id
))
console
.
log
(
'
room_Id있는지:
'
,
Boolean
(
room_Id
))
console
.
log
(
'
room_Id.member1:
'
,
room_Id
.
member
)
console
.
log
(
'
room_Id.member1:
'
,
room_Id
.
member
)
if
(
Boolean
(
room_Id
))
{
if
(
Boolean
(
room_Id
))
{
//roomId에 일치하는 방이 존재할때
//roomId에 일치하는 방의 member정보에 userId 저장하기
//roomId에 일치하는 방의 member정보에 userId 저장하기
const
matchedUserId
=
room_Id
.
member
.
filter
(
memberId
=>
memberId
===
userId
)
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
console
.
log
(
'
matchedUserId:
'
,
matchedUserId
)
const
includeUserId
=
room_Id
.
member
.
includes
(
parseInt
(
userId
));
// if (matchedUserId.length === 0) {
console
.
log
(
'
Include확인:
'
,
includeUserId
)
// room_Id.member.push(userId)
if
(
!
includeUserId
)
{
//아직 참여되지 않은 방인경우
// }
room_Id
.
member
.
push
(
userId
)
//member에 userId추가
// else {
console
.
log
(
'
room_Id.member2:
'
,
room_Id
.
member
)
// return res.status(422).send('이미 참여된 방입니다.')
await
Room
.
update
({
'
member
'
:
room_Id
.
member
},
{
where
:
{
id
:
roomId
}
})
// }
const
roomID
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
room_Id
.
member
.
push
(
userId
)
console
.
log
(
'
room_Id2:
'
,
roomID
.
member
)
//update됬는지 확인
console
.
log
(
'
room_Id.member2:
'
,
room_Id
.
member
)
await
Room
.
update
({
'
member
'
:
room_Id
.
member
},
{
where
:
{
id
:
roomId
}
})
const
roomID
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
console
.
log
(
'
room_Id2:
'
,
roomID
.
member
)
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
console
.
log
(
'
user_Id:
'
,
user_Id
)
// console.log('user_Id:', user_Id)
const
matchedRoomId
=
user_Id
.
roomNumber
.
filter
(
roomNum
=>
roomNum
===
roomId
)
console
.
log
(
'
user_Id.roomNumber1:
'
,
user_Id
.
roomNumber
)
console
.
log
(
'
matchedRoomId:
'
,
matchedRoomId
)
console
.
log
(
'
user_Id.roomNumber2:
'
,
Boolean
(
user_Id
.
roomNumber
))
console
.
log
(
'
matchedRoomId boo:
'
,
Boolean
(
matchedRoomId
))
if
(
Boolean
(
user_Id
.
roomNumber
))
{
//다른 roomNumber가 이미 들어가 있는 경우 roomId추가
console
.
log
(
'
user_Id.roomNumber1:
'
,
user_Id
.
roomNumber
)
user_Id
.
roomNumber
.
push
(
roomId
)
console
.
log
(
'
user_Id.roomNumber1:
'
,
Boolean
(
user_Id
.
roomNumber
))
}
if
(
Boolean
(
user_Id
.
roomNumber
))
{
else
{
//첫 roomNumber인 경우
user_Id
.
roomNumber
.
push
(
roomId
)
user_Id
.
roomNumber
=
[
roomId
]
}
console
.
log
(
'
user_Id.roomNumber2:
'
,
user_Id
.
roomNumber
)
await
User
.
update
({
'
roomNumber
'
:
user_Id
.
roomNumber
},
{
where
:
{
id
:
userId
}
})
const
userID
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
console
.
log
(
'
user_Id2:
'
,
userID
.
roomNumber
)
}
else
{
return
res
.
status
(
422
).
send
(
'
이미 참여된 방입니다.
'
)
}
}
else
{
user_Id
.
roomNumber
=
[
roomId
]
}
console
.
log
(
'
user_Id.roomNumber2:
'
,
user_Id
.
roomNumber
)
await
User
.
update
({
'
roomNumber
'
:
user_Id
.
roomNumber
},
{
where
:
{
id
:
userId
}
})
const
userID
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
console
.
log
(
'
user_Id2:
'
,
userID
.
roomNumber
)
}
else
{
}
else
{
return
res
.
status
(
422
).
send
(
'
참여코드와 일치하는 방이 존재하지 않습니다.
'
)
return
res
.
status
(
422
).
send
(
'
참여코드와 일치하는 방이 존재하지 않습니다.
'
)
}
}
...
...
index.js
View file @
0560f339
...
@@ -25,8 +25,8 @@ sequelize
...
@@ -25,8 +25,8 @@ sequelize
await
Room
.
create
({
await
Room
.
create
({
id
:
"
1234567890
"
,
id
:
"
1234567890
"
,
name
:
"
room
"
,
name
:
"
room
"
,
owner
:
"
8888
"
,
owner
:
8888
,
member
:
[
'
8888
'
],
member
:
[
8888
],
profileimg
:
"
C:
\
fakepath
\
스크린샷(1).png
"
,
profileimg
:
"
C:
\
fakepath
\
스크린샷(1).png
"
,
});
});
...
...
models/room.model.js
View file @
0560f339
...
@@ -12,7 +12,7 @@ const RoomModel = (sequelize) => {
...
@@ -12,7 +12,7 @@ const RoomModel = (sequelize) => {
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
},
},
owner
:
{
owner
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
INTEGER
,
},
},
member
:
{
member
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
INTEGER
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
INTEGER
),
...
...
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