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
0804ee25
Commit
0804ee25
authored
Jul 26, 2021
by
seoyeon
Browse files
Merge remote-tracking branch 'origin/jiweon827' into seoyeon2
parents
ac15b407
231fc9bd
Changes
11
Show whitespace changes
Inline
Side-by-side
client/src/apis/user.api.js
View file @
0804ee25
import
axios
from
"
axios
"
;
import
axios
from
"
axios
"
;
const
getUser
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
get
(
"
/api/user
"
,
payload
);
return
data
;
};
const
login
=
async
(
payload
)
=>
{
const
login
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/login
"
,
payload
);
const
{
data
}
=
await
axios
.
post
(
"
/api/login
"
,
payload
);
return
data
;
return
data
;
...
@@ -10,6 +15,6 @@ const signup = async (payload) => {
...
@@ -10,6 +15,6 @@ const signup = async (payload) => {
return
data
;
return
data
;
};
};
const
userApi
=
{
login
,
signup
};
const
userApi
=
{
getUser
,
login
,
signup
};
export
default
userApi
;
export
default
userApi
;
client/src/components/Home/AddRoom.js
View file @
0804ee25
...
@@ -45,6 +45,7 @@ const AddRoom = () => {
...
@@ -45,6 +45,7 @@ const AddRoom = () => {
className
=
"
p-3
"
className
=
"
p-3
"
data
-
bs
-
toggle
=
"
modal
"
data
-
bs
-
toggle
=
"
modal
"
data
-
bs
-
target
=
"
#joinModal
"
data
-
bs
-
target
=
"
#joinModal
"
// data-bs-dismiss="modal"
style
=
{{
style
=
{{
display
:
"
flex
"
,
display
:
"
flex
"
,
flexDirection
:
"
column
"
,
flexDirection
:
"
column
"
,
...
@@ -73,6 +74,7 @@ const AddRoom = () => {
...
@@ -73,6 +74,7 @@ const AddRoom = () => {
className
=
"
p-3
"
className
=
"
p-3
"
data
-
bs
-
toggle
=
"
modal
"
data
-
bs
-
toggle
=
"
modal
"
data
-
bs
-
target
=
"
#makeModal
"
data
-
bs
-
target
=
"
#makeModal
"
// data-bs-dismiss="modal"
style
=
{{
style
=
{{
display
:
"
flex
"
,
display
:
"
flex
"
,
flexDirection
:
"
column
"
,
flexDirection
:
"
column
"
,
...
...
client/src/components/Home/CreateRoom.js
View file @
0804ee25
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
Redirect
}
from
"
react-router-dom
"
;
import
roomApi
from
"
../../apis/room.api
"
;
import
roomApi
from
"
../../apis/room.api
"
;
const
userId
=
localStorage
.
getItem
(
'
user
'
);
const
userId
=
localStorage
.
getItem
(
'
user
'
);
console
.
log
(
userId
)
console
.
log
(
userId
)
const
INIT_ROOM
=
{
const
INIT_ROOM
=
{
name
:
''
,
name
:
''
,
owner
:
userId
,
member
:
userId
,
profileimg
:
''
,
profileimg
:
''
,
channel
:
[
'
회의
'
],
}
}
const
CreateRoom
=
()
=>
{
const
CreateRoom
=
()
=>
{
...
@@ -20,11 +22,6 @@ const CreateRoom = () => {
...
@@ -20,11 +22,6 @@ const CreateRoom = () => {
isRoom
?
setDisabled
(
false
)
:
setDisabled
(
true
);
isRoom
?
setDisabled
(
false
)
:
setDisabled
(
true
);
},
[
room
]);
},
[
room
]);
// const userId = localStorage.getItem('user');
// setRoom({...room, owner: userId})
// setRoom({...room, member: userId})
function
handleChange
(
event
)
{
function
handleChange
(
event
)
{
console
.
log
(
room
)
console
.
log
(
room
)
const
{
name
,
value
}
=
event
.
target
const
{
name
,
value
}
=
event
.
target
...
@@ -39,9 +36,9 @@ const CreateRoom = () => {
...
@@ -39,9 +36,9 @@ const CreateRoom = () => {
const
res
=
await
roomApi
.
create
(
room
)
const
res
=
await
roomApi
.
create
(
room
)
// console.log(res)
// console.log(res)
const
Id
=
res
.
id
const
Id
=
res
.
id
//
console.log(Id)
console
.
log
(
Id
)
//
alert(`방참여코드는 ${Id}입니다`)
alert
(
`방참여코드는
${
Id
}
입니다`
)
//
setSuccess(true)
setSuccess
(
true
)
}
catch
(
error
)
{
}
catch
(
error
)
{
// catchErrors(error, setError);
// catchErrors(error, setError);
}
finally
{
}
finally
{
...
@@ -52,7 +49,7 @@ const CreateRoom = () => {
...
@@ -52,7 +49,7 @@ const CreateRoom = () => {
if
(
success
)
{
if
(
success
)
{
console
.
log
(
'
success
'
,
success
)
console
.
log
(
'
success
'
,
success
)
alert
(
'
룸생성이 완료되었습니다!
'
)
alert
(
'
룸생성이 완료되었습니다!
'
)
//
return <Redirect to='/' />
return
<
Redirect
to
=
'
/
user
'
/>
}
}
const
{
name
,
owner
,
member
,
profileimg
}
=
room
;
const
{
name
,
owner
,
member
,
profileimg
}
=
room
;
...
...
client/src/components/Home/HomeProfile.js
View file @
0804ee25
import
{
Link
}
from
"
react-router-dom
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
import
userApi
from
"
../../apis/user.api
"
;
const
INIT_USER
=
{
id
:
''
,
name
:
''
,
img
:
''
,
}
const
HomeProfile
=
()
=>
{
const
HomeProfile
=
()
=>
{
const
id
=
1
;
const
[
user
,
setUser
]
=
useState
(
INIT_USER
)
const
id
=
localStorage
.
getItem
(
'
user
'
);
async
function
getUser
(
id
)
{
try
{
// `/users/${userId}`랑 userId랑 같은지 확인
const
User
=
await
userApi
.
user
(
id
)
console
.
log
(
User
)
setUser
(
User
.
data
)
console
.
log
(
user
)
}
catch
(
error
)
{
// catchErrors(error, setError)
}
}
useEffect
(()
=>
{
getUser
(
id
)
},
[
id
])
return
(
return
(
<
Link
to
=
{
`/profile/
${
id
}
`
}
className
=
"
text-decoration-none text-dark
"
>
<
Link
to
=
{
`/profile/
${
id
}
`
}
className
=
"
text-decoration-none text-dark
"
>
<
form
className
=
"
flex-column align-items-center justify-content-center m-2
"
>
<
form
className
=
"
flex-column align-items-center justify-content-center m-2
"
>
<
div
className
=
"
d-flex justify-content-center
"
>
<
div
className
=
"
d-flex justify-content-center
"
>
<
img
<
img
src
=
"
cherry.jpg
"
//
src="cherry.jpg"
className
=
"
rounded-circle
"
className
=
"
rounded-circle
"
style
=
{{
style
=
{{
width
:
"
157px
"
,
width
:
"
157px
"
,
height
:
"
157px
"
,
height
:
"
157px
"
,
}}
}}
value
=
{
user
.
img
}
/
>
/
>
<
/div
>
<
/div
>
<
h1
className
=
"
d-flex justify-content-center
"
>
CHERRY
<
/h1
>
<
h1
className
=
"
d-flex justify-content-center
"
>
{
user
.
name
}
<
/h1
>
<
h2
className
=
"
d-flex justify-content-center
"
>
#
0805
<
/h2
>
<
h2
className
=
"
d-flex justify-content-center
"
>
#
{
user
.
id
}
<
/h2
>
<
/form
>
<
/form
>
<
div
<
div
style
=
{{
backgroundColor
:
"
#262626
"
,
width
:
"
auto
"
,
height
:
"
2px
"
}}
style
=
{{
backgroundColor
:
"
#262626
"
,
width
:
"
auto
"
,
height
:
"
2px
"
}}
...
...
client/src/components/Home/JoinRoom.js
View file @
0804ee25
...
@@ -26,9 +26,9 @@ const JoinRoom = () => {
...
@@ -26,9 +26,9 @@ const JoinRoom = () => {
try
{
try
{
// setLoading(true);
// setLoading(true);
// setError("");
// setError("");
console
.
log
(
'
userId:
'
,
userId
)
console
.
log
(
'
userId:
'
,
userId
)
console
.
log
(
'
roomId:
'
,
roomId
)
console
.
log
(
'
roomId:
'
,
roomId
)
const
data
=
await
roomApi
.
join
({
userId
:
userId
,
roomId
:
roomId
});
const
data
=
await
roomApi
.
join
({
userId
:
userId
,
roomId
:
roomId
});
console
.
log
(
data
);
console
.
log
(
data
);
setSuccess
(
true
);
setSuccess
(
true
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -38,6 +38,7 @@ const JoinRoom = () => {
...
@@ -38,6 +38,7 @@ const JoinRoom = () => {
}
}
}
}
if
(
success
)
{
if
(
success
)
{
return
<
Redirect
to
=
"
/user
"
/>
;
}
}
return
(
return
(
...
...
controllers/room.controller.js
View file @
0804ee25
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
config
from
"
../config/app.config.js
"
;
import
isLength
from
'
validator/lib/isLength.js
'
import
isLength
from
'
validator/lib/isLength.js
'
...
@@ -8,82 +9,74 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
...
@@ -8,82 +9,74 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
const
joinRoom
=
async
(
req
,
res
)
=>
{
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
console
.
log
(
'
userId:
'
,
userId
)
console
.
log
(
'
roomId:
'
,
roomId
)
const
room_Id
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
const
room_Id
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
console
.
log
(
'
room_Id:
'
,
room_Id
)
console
.
log
(
'
room_Id1:
'
,
room_Id
)
if
(
room_Id
)
{
console
.
log
(
'
room_Id있는지:
'
,
Boolean
(
room_Id
))
//roomId에 일치하는 방의 member정보에 userId 저장하기
console
.
log
(
'
room_Id.member1:
'
,
room_Id
.
member
)
console
.
log
(
'
room_Id.member1:
'
,
room_Id
.
member
)
if
(
Boolean
(
room_Id
))
{
//roomId에 일치하는 방의 member정보에 userId 저장하기
const
matchedUserId
=
room_Id
.
member
.
filter
(
memberId
=>
memberId
===
userId
)
console
.
log
(
'
matchedUserId:
'
,
matchedUserId
)
// if (matchedUserId.length === 0) {
// room_Id.member.push(userId)
// }
// else {
// return res.status(422).send('이미 참여된 방입니다.')
// }
room_Id
.
member
.
push
(
userId
)
room_Id
.
member
.
push
(
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
}
})
await
Room
.
update
({
'
member
'
:
room_Id
.
member
},
{
where
:
{
id
:
roomId
}
})
const
roomID
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
const
roomID
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
console
.
log
(
'
room_Id2:
'
,
roomID
.
member
)
console
.
log
(
'
room_Id2:
'
,
roomID
.
member
)
//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)
// user_Id.roomNumber.push(roomId)
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
// await User.update({ 'roomNumber': roomId }, { where: { id: userId } })
// const userID = await User.findOne({ where: { id: userId } });
// console.log('user_Id2:', userID.roomNumber)
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
console
.
log
(
'
user_Id:
'
,
user_Id
)
const
matchedRoomId
=
user_Id
.
roomNumber
.
filter
(
roomNum
=>
roomNum
===
roomId
)
console
.
log
(
'
matchedRoomId:
'
,
matchedRoomId
)
console
.
log
(
'
matchedRoomId boo:
'
,
Boolean
(
matchedRoomId
))
console
.
log
(
'
user_Id.roomNumber1:
'
,
user_Id
.
roomNumber
)
console
.
log
(
'
user_Id.roomNumber1:
'
,
Boolean
(
user_Id
.
roomNumber
))
if
(
Boolean
(
user_Id
.
roomNumber
))
{
user_Id
.
roomNumber
.
push
(
roomId
)
}
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
(
'
참여코드와 일치하는 방이 존재하지 않습니다.
'
)
}
}
};
};
// 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)
// indexOf : userId가 몇번째 인덱스인지 찾기
// try {
// if (isPresent < 0) {
// const memberId = room.member.push(userId)
// await Room.updateOne({ 'roomId': roomId }, { 'member': room.member })
// // console.log('room.member 업데이트 완료')
// return res.json(true)
// }
// else {
// return res.json(false)
// }
// } catch (error) {
// res.status(500).send('멤버 업데이트 실패')
// }
// }
const
createRoom
=
async
(
req
,
res
)
=>
{
const
createRoom
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
룸정보
'
,
req
.
body
)
console
.
log
(
'
룸정보
'
,
req
.
body
)
const
{
name
,
owner
,
member
,
profileimg
,
channel
}
=
req
.
body
;
const
{
name
,
owner
,
member
,
profileimg
}
=
req
.
body
;
console
.
log
(
'
owner:
'
,
owner
)
const
id
=
nanoid
()
const
id
=
nanoid
()
console
.
log
(
'
id:
'
,
id
)
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
console
.
log
(
"
Id중복확인:
"
,
I
d
)
console
.
log
(
'
id:
'
,
i
d
)
while
(
Id
)
{
while
(
Boolean
(
Id
)
)
{
const
id
=
nanoid
()
const
id
=
nanoid
()
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
}
}
try
{
try
{
if
(
!
isLength
(
name
,
{
min
:
3
,
max
:
20
}))
{
if
(
!
isLength
(
name
,
{
min
:
3
,
max
:
20
}))
{
console
.
log
(
'
방이름은 3-20자여야 합니다.
'
)
console
.
log
(
'
방이름은 3-20자여야 합니다.
'
)
return
res
.
status
(
422
).
send
(
'
방이름은 3-20자여야 합니다.
'
)
return
res
.
status
(
422
).
send
(
'
방이름은 3-20자여야 합니다.
'
)
}
}
const
newRoom
=
{
const
newRoom
=
await
Room
.
create
({
id
:
id
,
id
:
id
,
name
:
name
,
name
:
name
,
owner
:
owner
,
owner
:
owner
,
member
:
member
,
member
:
[
member
]
,
profileimg
:
profileimg
,
profileimg
:
profileimg
,
channel
:
channel
,
}
}).
then
(
_
=>
console
.
log
(
'
room정보:
'
,
id
,
name
,
owner
,
member
,
profileimg
,
channel
))
console
.
log
(
'
newRoom:
'
,
newRoom
)
console
.
log
(
'
newRoom:
'
,
newRoom
)
await
Room
.
create
(
newRoom
)
console
.
log
(
'
room정보:
'
,
id
,
name
,
owner
,
[
member
],
profileimg
)
res
.
json
(
newRoom
)
res
.
json
(
newRoom
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
...
...
controllers/user.controller.js
View file @
0804ee25
...
@@ -2,7 +2,13 @@ import { User } from '../models/index.js'
...
@@ -2,7 +2,13 @@ import { User } from '../models/index.js'
import
jwt
from
'
jsonwebtoken
'
import
jwt
from
'
jsonwebtoken
'
import
config
from
'
../config/app.config.js
'
import
config
from
'
../config/app.config.js
'
import
isLength
from
'
validator/lib/isLength.js
'
import
isLength
from
'
validator/lib/isLength.js
'
import
bcrypt
from
'
bcryptjs
'
import
bcrypt
from
"
bcryptjs
"
;
const
user
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
const
user
=
await
User
.
findAll
({
where
:
{
id
:
req
.
body
}
});
req
.
json
(
user
)
};
const
login
=
async
(
req
,
res
)
=>
{
const
login
=
async
(
req
,
res
)
=>
{
try
{
try
{
...
@@ -79,6 +85,7 @@ const logout = (req, res) => {
...
@@ -79,6 +85,7 @@ const logout = (req, res) => {
}
}
export
default
{
export
default
{
user
,
login
,
login
,
signup
,
signup
,
logout
,
logout
,
...
...
index.js
View file @
0804ee25
...
@@ -25,10 +25,9 @@ sequelize
...
@@ -25,10 +25,9 @@ sequelize
await
Room
.
create
({
await
Room
.
create
({
id
:
"
1234567890
"
,
id
:
"
1234567890
"
,
name
:
"
room
"
,
name
:
"
room
"
,
owner
:
[
'
600112d16d09ac6b7892d900
'
]
,
owner
:
"
8888
"
,
member
:
[
'
600112d16d09ac6b7892d900
'
],
member
:
[
'
8888
'
],
profileimg
:
"
C:
\
fakepath
\
스크린샷(1).png
"
,
profileimg
:
"
C:
\
fakepath
\
스크린샷(1).png
"
,
channel
:
[
'
회의
'
],
});
});
app
.
listen
(
appConfig
.
port
,
()
=>
{
app
.
listen
(
appConfig
.
port
,
()
=>
{
...
...
models/room.model.js
View file @
0804ee25
...
@@ -12,16 +12,19 @@ const RoomModel = (sequelize) => {
...
@@ -12,16 +12,19 @@ const RoomModel = (sequelize) => {
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
},
},
owner
:
{
owner
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
)
,
type
:
DataTypes
.
STRING
,
},
},
member
:
{
member
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
INTEGER
),
//type: DataTypes.STRING,
},
},
profileimg
:
{
profileimg
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
defaultValue
:
"
/user.png
"
},
},
channel
:
{
channel
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
JSON
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
JSON
),
defaultValue
:
[{
'
회의
'
:
""
}],
},
},
},
},
{
timestamps
:
true
}
{
timestamps
:
true
}
...
...
models/user.model.js
View file @
0804ee25
...
@@ -28,9 +28,9 @@ const UserModel = (sequelize) => {
...
@@ -28,9 +28,9 @@ const UserModel = (sequelize) => {
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
defaultValue
:
"
/user.png
"
defaultValue
:
"
/user.png
"
},
},
//
roomNumber: {
roomNumber
:
{
//
type: DataTypes.ARRAY(DataTypes.STRING),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
//
},
},
},
},
{
timestamps
:
true
}
{
timestamps
:
true
}
);
);
...
...
routes/user.route.js
View file @
0804ee25
...
@@ -3,6 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
...
@@ -3,6 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
.
route
(
"
/getUser
"
).
get
(
userCtrl
.
user
);
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
signup
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
signup
);
...
...
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