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
231fc9bd
Commit
231fc9bd
authored
Jul 26, 2021
by
우지원
Browse files
0726
parent
993db9c8
Changes
4
Show whitespace changes
Inline
Side-by-side
controllers/room.controller.js
View file @
231fc9bd
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
'
...
@@ -11,41 +12,41 @@ const joinRoom = async (req, res) => {
...
@@ -11,41 +12,41 @@ const joinRoom = async (req, res) => {
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
)
if
(
Boolean
(
room_Id
))
{
if
(
Boolean
(
room_Id
))
{
//roomId에 일치하는 방의 member정보에 userId 저장하기
//roomId에 일치하는 방의 member정보에 userId 저장하기
const
userInter
=
await
Room
.
findOne
({
const
matchedUserId
=
room_Id
.
member
.
filter
(
memberId
=>
memberId
===
userId
)
where
:
{
id
:
roomId
},
console
.
log
(
'
matchedUserId:
'
,
matchedUserId
)
Include
:
{
member
:
userId
}
// if (matchedUserId.length === 0) {
}).
then
(
_
=>
console
.
log
(
'
userInter되었습니다!
'
));
// room_Id.member.push(userId)
//const userInter = await Room.findOne({ Include: [{ id: roomId}, {member: userId}] });
// }
console
.
log
(
'
userInter:
'
,
userInter
)
// else {
console
.
log
(
'
userId:
'
,
userId
)
// return res.status(422).send('이미 참여된 방입니다.')
if
(
Boolean
(
userInter
))
{
// }
return
res
.
status
(
422
).
send
(
'
이미 참여된 방입니다.
'
)
}
else
{
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저장하기
//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
(
'
matchedRoomId:
'
,
matchedRoomId
)
console
.
log
(
'
matchedRoomId boo:
'
,
Boolean
(
matchedRoomId
))
console
.
log
(
'
user_Id.roomNumber1:
'
,
user_Id
.
roomNumber
)
console
.
log
(
'
user_Id.roomNumber1:
'
,
user_Id
.
roomNumber
)
if
(
user_Id
.
roomNumber
)
{
console
.
log
(
'
user_Id.roomNumber1:
'
,
Boolean
(
user_Id
.
roomNumber
))
if
(
Boolean
(
user_Id
.
roomNumber
))
{
user_Id
.
roomNumber
.
push
(
roomId
)
user_Id
.
roomNumber
.
push
(
roomId
)
}
}
else
{
else
{
user_Id
.
roomNumber
=
roomId
user_Id
.
roomNumber
=
[
roomId
]
}
console
.
log
(
'
user_Id.roomNumber2:
'
,
[
user_Id
.
roomNumber
])
await
User
.
update
({
'
roomNumber
'
:
[
user_Id
.
roomNumber
]
},
{
where
:
{
id
:
userId
}
})
// .then(_ => res.json(true))
// const userID = await User.findOne({ where: { id: userId } });
// console.log('user_Id2:', userID.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
{
}
else
{
return
res
.
status
(
422
).
send
(
'
참여코드와 일치하는 방이 존재하지 않습니다.
'
)
return
res
.
status
(
422
).
send
(
'
참여코드와 일치하는 방이 존재하지 않습니다.
'
)
}
}
...
@@ -74,7 +75,8 @@ const createRoom = async (req, res) => {
...
@@ -74,7 +75,8 @@ const createRoom = async (req, res) => {
profileimg
:
profileimg
,
profileimg
:
profileimg
,
}
}
console
.
log
(
'
newRoom:
'
,
newRoom
)
console
.
log
(
'
newRoom:
'
,
newRoom
)
await
Room
.
create
(
newRoom
).
then
(
_
=>
console
.
log
(
'
room정보:
'
,
id
,
name
,
owner
,
[
member
],
profileimg
))
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
)
...
...
index.js
View file @
231fc9bd
...
@@ -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 @
231fc9bd
...
@@ -15,14 +15,16 @@ const RoomModel = (sequelize) => {
...
@@ -15,14 +15,16 @@ const RoomModel = (sequelize) => {
type
:
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
:
[
'
회의
'
],
defaultValue
:
[
{
'
회의
'
:
""
}
],
},
},
},
},
{
timestamps
:
true
}
{
timestamps
:
true
}
...
...
models/user.model.js
View file @
231fc9bd
...
@@ -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
}
);
);
...
...
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