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
Hide whitespace changes
Inline
Side-by-side
controllers/room.controller.js
View file @
231fc9bd
import
{
Room
,
User
}
from
"
../models/index.js
"
;
import
{
customAlphabet
}
from
'
nanoid
'
import
{
Op
}
from
'
sequelize
'
;
import
config
from
"
../config/app.config.js
"
;
import
isLength
from
'
validator/lib/isLength.js
'
...
...
@@ -11,41 +12,41 @@ const joinRoom = async (req, res) => {
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에 일치하는 방의 member정보에 userId 저장하기
const
userInter
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
},
Include
:
{
member
:
userId
}
}).
then
(
_
=>
console
.
log
(
'
userInter되었습니다!
'
));
//const userInter = await Room.findOne({ Include: [{ id: roomId}, {member: userId}] });
console
.
log
(
'
userInter:
'
,
userInter
)
console
.
log
(
'
userId:
'
,
userId
)
if
(
Boolean
(
userInter
))
{
return
res
.
status
(
422
).
send
(
'
이미 참여된 방입니다.
'
)
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
)
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저장하기
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
{
room_Id
.
member
.
push
(
userId
)
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저장하기
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
console
.
log
(
'
user_Id:
'
,
user_Id
)
console
.
log
(
'
user_Id.roomNumber1:
'
,
user_Id
.
roomNumber
)
if
(
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
}
})
// .then(_ => res.json(true))
// const userID = await User.findOne({ where: { id: userId } });
// console.log('user_Id2:', userID.roomNumber)
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
(
'
참여코드와 일치하는 방이 존재하지 않습니다.
'
)
}
...
...
@@ -74,7 +75,8 @@ const createRoom = async (req, res) => {
profileimg
:
profileimg
,
}
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
)
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
index.js
View file @
231fc9bd
...
...
@@ -25,10 +25,9 @@ sequelize
await
Room
.
create
({
id
:
"
1234567890
"
,
name
:
"
room
"
,
owner
:
"
600112d16d09ac6b7892d900
"
,
member
:
[
'
600112d16d09ac6b7892d900
'
],
owner
:
"
8888
"
,
member
:
[
'
8888
'
],
profileimg
:
"
C:
\
fakepath
\
스크린샷(1).png
"
,
channel
:
[
'
회의
'
],
});
app
.
listen
(
appConfig
.
port
,
()
=>
{
...
...
models/room.model.js
View file @
231fc9bd
...
...
@@ -15,14 +15,16 @@ const RoomModel = (sequelize) => {
type
:
DataTypes
.
STRING
,
},
member
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
INTEGER
),
//type: DataTypes.STRING,
},
profileimg
:
{
type
:
DataTypes
.
STRING
,
defaultValue
:
"
/user.png
"
},
channel
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
JSON
),
defaultValue
:
[
'
회의
'
],
defaultValue
:
[
{
'
회의
'
:
""
}
],
},
},
{
timestamps
:
true
}
...
...
models/user.model.js
View file @
231fc9bd
...
...
@@ -28,9 +28,9 @@ const UserModel = (sequelize) => {
type
:
DataTypes
.
STRING
,
defaultValue
:
"
/user.png
"
},
//
roomNumber: {
//
type: DataTypes.ARRAY(DataTypes.STRING),
//
},
roomNumber
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
},
},
{
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