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
fa2eeb1e
Commit
fa2eeb1e
authored
Jul 27, 2021
by
우지원
Browse files
0727
parent
245ddecd
Changes
4
Hide whitespace changes
Inline
Side-by-side
client/src/components/Home/CreateRoom.js
View file @
fa2eeb1e
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
Redirect
}
from
"
react-router-dom
"
;
import
roomApi
from
"
../../apis/room.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
userId
=
localStorage
.
getItem
(
'
user
'
);
console
.
log
(
userId
)
...
...
@@ -40,7 +41,7 @@ const CreateRoom = () => {
alert
(
`방참여코드는
${
Id
}
입니다`
)
setSuccess
(
true
)
}
catch
(
error
)
{
//
catchErrors(error, setError);
catchErrors
(
error
,
setError
);
}
finally
{
// setLoading(false);
}
...
...
client/src/components/Home/RoomSingle.js
View file @
fa2eeb1e
...
...
@@ -10,9 +10,12 @@ const RoomSingle = () => {
const
id
=
localStorage
.
getItem
(
'
user
'
);
const
channelId
=
1
async
function
getJoinRoom
(
i
d
)
{
async
function
getJoinRoom
(
I
d
)
{
try
{
const
User
=
await
userApi
.
getUser
(
id
)
console
.
log
(
'
id:
'
,
id
)
const
User
=
await
userApi
.
getUser
({
id
:
Id
})
console
.
log
(
'
User1:
'
,
User
)
console
.
log
(
'
User2:
'
,
User
.
roomNumber
)
setRoomNum
(
User
.
data
.
roomNumber
)
const
Room
=
await
roomApi
.
getRoom
(
roomNum
)
}
catch
(
error
)
{
...
...
controllers/room.controller.js
View file @
fa2eeb1e
...
...
@@ -5,39 +5,28 @@ import isLength from 'validator/lib/isLength.js'
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
joinRoom
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
req.body.value:
'
,
req
.
body
)
const
{
userId
,
roomId
}
=
req
.
body
const
room_Id
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
// console.log('room_Id1:', room_Id)
console
.
log
(
'
room_Id있는지:
'
,
Boolean
(
room_Id
))
console
.
log
(
'
room_Id.member1:
'
,
room_Id
.
member
)
if
(
Boolean
(
room_Id
))
{
//roomId에 일치하는 방이 존재할때
//roomId에 일치하는 방의 member정보에 userId 저장하기
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
const
includeUserId
=
room_Id
.
member
.
includes
(
parseInt
(
userId
));
console
.
log
(
'
Include확인:
'
,
includeUserId
)
//
console.log('Include확인:',includeUserId)
if
(
!
includeUserId
)
{
//아직 참여되지 않은 방인경우
room_Id
.
member
.
push
(
userId
)
//member에 userId추가
console
.
log
(
'
room_Id.member2:
'
,
room_Id
.
member
)
//
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
)
//update됬는지 확인
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
// console.log('user_Id:', user_Id)
console
.
log
(
'
user_Id.roomNumber1:
'
,
user_Id
.
roomNumber
)
console
.
log
(
'
user_Id.roomNumber2:
'
,
Boolean
(
user_Id
.
roomNumber
))
if
(
Boolean
(
user_Id
.
roomNumber
))
{
//다른 roomNumber가 이미 들어가 있는 경우 roomId추가
user_Id
.
roomNumber
.
push
(
roomId
)
}
else
{
//첫 roomNumber인 경우
user_Id
.
roomNumber
=
[
roomId
]
}
console
.
log
(
'
user_Id.roomNumber2:
'
,
user_Id
.
roomNumber
)
//
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
(
'
이미 참여된 방입니다.
'
)
}
...
...
@@ -51,16 +40,16 @@ const createRoom = async (req, res) => {
const
{
name
,
owner
,
member
,
profileimg
}
=
req
.
body
;
const
id
=
nanoid
()
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
console
.
log
(
'
id:
'
,
id
)
//
console.log('id:', id)
while
(
Boolean
(
Id
))
{
const
id
=
nanoid
()
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
}
try
{
if
(
!
isLength
(
name
,
{
min
:
3
,
max
:
20
}))
{
console
.
log
(
'
방이름은 3-20자여야 합니다.
'
)
return
res
.
status
(
422
).
send
(
'
방이름은 3-20자여야 합니다.
'
)
}
//새로운 RoomDB생성
const
newRoom
=
{
id
:
id
,
name
:
name
,
...
...
@@ -68,9 +57,19 @@ const createRoom = async (req, res) => {
member
:
[
member
],
profileimg
:
profileimg
,
}
console
.
log
(
'
newRoom:
'
,
newRoom
)
//
console.log('newRoom:', newRoom)
await
Room
.
create
(
newRoom
)
console
.
log
(
'
room정보:
'
,
id
,
name
,
owner
,
[
member
],
profileimg
)
//user.roomNumber에 id추가
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
owner
}
});
if
(
Boolean
(
user_Id
.
roomNumber
))
{
//다른 roomNumber가 이미 들어가 있는 경우 id추가
user_Id
.
roomNumber
.
push
(
id
)
}
else
{
//첫 roomNumber인 경우
user_Id
.
roomNumber
=
[
id
]
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await
User
.
update
({
'
roomNumber
'
:
user_Id
.
roomNumber
},
{
where
:
{
id
:
owner
}
})
res
.
json
(
newRoom
)
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
controllers/user.controller.js
View file @
fa2eeb1e
...
...
@@ -5,12 +5,8 @@ import isLength from 'validator/lib/isLength.js'
import
bcrypt
from
"
bcryptjs
"
;
const
getUser
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
유저가져왔다아아아ㅏㅇ:
'
,
req
.
body
)
console
.
log
(
'
id:
'
,
req
.
body
.
id
)
const
id
=
req
.
body
.
id
const
user
=
await
User
.
findOne
({
where
:
{
id
:
id
}
});
console
.
log
(
'
user:
'
,
user
)
req
.
json
(
user
)
const
user
=
await
User
.
findOne
({
where
:
{
id
:
req
.
body
.
id
}
});
res
.
json
(
user
)
};
const
login
=
async
(
req
,
res
)
=>
{
...
...
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