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
8385db83
Commit
8385db83
authored
Aug 09, 2021
by
이재연
Browse files
머지하세용 ㅋ
parent
76c3e723
Changes
19
Hide whitespace changes
Inline
Side-by-side
client/src/apis/room.api.js
View file @
8385db83
...
@@ -37,6 +37,13 @@ const doubleJoin = async (payload) => {
...
@@ -37,6 +37,13 @@ const doubleJoin = async (payload) => {
return
data
;
return
data
;
};
};
const
removeRoom
=
async
(
ID
)
=>
{
const
{
data
}
=
await
axios
.
delete
(
`/api/room/removeRoom/
${
ID
.
roomId
}
`
);
return
data
;
}
// const makeChannel = async (payload) => {
// const makeChannel = async (payload) => {
// const { data } = await axios.post("/api/room/makeChannel", payload);
// const { data } = await axios.post("/api/room/makeChannel", payload);
// return data;
// return data;
...
@@ -50,6 +57,7 @@ const roomApi = {
...
@@ -50,6 +57,7 @@ const roomApi = {
changename
,
changename
,
joinChannel
,
joinChannel
,
doubleJoin
,
doubleJoin
,
removeRoom
};
};
export
default
roomApi
;
export
default
roomApi
;
client/src/components/Header.js
View file @
8385db83
...
@@ -2,7 +2,7 @@ import { Link } from 'react-router-dom'
...
@@ -2,7 +2,7 @@ import { Link } from 'react-router-dom'
import
{
handleLogout
}
from
'
../context/auth
'
import
{
handleLogout
}
from
'
../context/auth
'
const
Header
=
()
=>
{
const
Header
=
()
=>
{
const
id
=
local
Storage
.
getItem
(
'
user
'
);
const
id
=
session
Storage
.
getItem
(
'
user
'
);
return
(
return
(
<
div
>
<
div
>
<
form
<
form
...
...
client/src/components/Home/CreateRoom.js
View file @
8385db83
...
@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
...
@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
import
roomApi
from
"
../../apis/room.api
"
;
import
roomApi
from
"
../../apis/room.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
id
=
local
Storage
.
getItem
(
'
user
'
);
const
id
=
session
Storage
.
getItem
(
'
user
'
);
const
INIT_ROOM
=
{
const
INIT_ROOM
=
{
name
:
''
,
name
:
''
,
profileimg
:
''
,
profileimg
:
''
,
...
...
client/src/components/Home/HomeProfile.js
View file @
8385db83
...
@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
...
@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import
userApi
from
"
../../apis/user.api
"
;
import
userApi
from
"
../../apis/user.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
userprofile
=
local
Storage
.
getItem
(
"
user
"
);
const
userprofile
=
session
Storage
.
getItem
(
"
user
"
);
const
INIT_USER
=
{
const
INIT_USER
=
{
id
:
userprofile
,
id
:
userprofile
,
email
:
""
,
email
:
""
,
...
...
client/src/components/Home/JoinRoom.js
View file @
8385db83
...
@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
...
@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
import
roomApi
from
"
../../apis/room.api
"
;
import
roomApi
from
"
../../apis/room.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
id
=
local
Storage
.
getItem
(
"
user
"
);
const
id
=
session
Storage
.
getItem
(
"
user
"
);
const
JoinRoom
=
()
=>
{
const
JoinRoom
=
()
=>
{
const
[
roomId
,
setRoomId
]
=
useState
(
""
);
const
[
roomId
,
setRoomId
]
=
useState
(
""
);
...
...
client/src/components/Home/RoomSingle.js
View file @
8385db83
...
@@ -4,7 +4,7 @@ import roomApi from "../../apis/room.api";
...
@@ -4,7 +4,7 @@ import roomApi from "../../apis/room.api";
import
userApi
from
"
../../apis/user.api
"
;
import
userApi
from
"
../../apis/user.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
id
=
local
Storage
.
getItem
(
"
user
"
);
const
id
=
session
Storage
.
getItem
(
"
user
"
);
const
INIT_ROOM
=
{
const
INIT_ROOM
=
{
roomId
:
""
,
roomId
:
""
,
name
:
""
,
name
:
""
,
...
...
client/src/components/KakaoShareButton.js
View file @
8385db83
...
@@ -13,7 +13,7 @@ const KakaoShareButton = (porps) => {
...
@@ -13,7 +13,7 @@ const KakaoShareButton = (porps) => {
const
[
inviteperson
,
setProfile
]
=
useState
(
INIT_invite
);
const
[
inviteperson
,
setProfile
]
=
useState
(
INIT_invite
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
{
roomId
}
=
useParams
();
const
{
roomId
}
=
useParams
();
const
invitepersonId
=
local
Storage
.
getItem
(
"
user
"
);
const
invitepersonId
=
session
Storage
.
getItem
(
"
user
"
);
async
function
getProfile
(
userID
)
{
async
function
getProfile
(
userID
)
{
try
{
try
{
...
...
client/src/components/Login.js
View file @
8385db83
...
@@ -46,7 +46,7 @@ const Login = () => {
...
@@ -46,7 +46,7 @@ const Login = () => {
}
}
if
(
success
)
{
if
(
success
)
{
alert
(
'
로그인 되었습니다
'
)
alert
(
'
로그인 되었습니다
'
)
return
<
Redirect
to
=
{
`/user/
${
id
}
`
}
/>
;
window
.
location
.
href
=
`/user/
${
id
}
`
}
}
const
{
email
,
password
}
=
user
const
{
email
,
password
}
=
user
...
...
client/src/components/Profile/Info.js
View file @
8385db83
...
@@ -2,7 +2,7 @@ import userApi from "../../apis/user.api";
...
@@ -2,7 +2,7 @@ import userApi from "../../apis/user.api";
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
userprofile
=
local
Storage
.
getItem
(
"
user
"
);
const
userprofile
=
session
Storage
.
getItem
(
"
user
"
);
const
INIT_PROFILE
=
{
const
INIT_PROFILE
=
{
name
:
""
,
name
:
""
,
email
:
"
a
"
,
email
:
"
a
"
,
...
...
client/src/components/Profile/InfoUpdate.js
View file @
8385db83
...
@@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";
...
@@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";
import
userApi
from
"
../../apis/user.api
"
;
import
userApi
from
"
../../apis/user.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
userprofile
=
local
Storage
.
getItem
(
"
user
"
);
const
userprofile
=
session
Storage
.
getItem
(
"
user
"
);
const
INIT_PROFILE
=
{
const
INIT_PROFILE
=
{
id
:
userprofile
,
id
:
userprofile
,
name
:
""
,
name
:
""
,
...
...
client/src/components/Profile/Profile.js
View file @
8385db83
...
@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
...
@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import
userApi
from
"
../../apis/user.api
"
;
import
userApi
from
"
../../apis/user.api
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
const
userprofile
=
local
Storage
.
getItem
(
"
user
"
);
const
userprofile
=
session
Storage
.
getItem
(
"
user
"
);
const
INIT_PROFILE
=
{
const
INIT_PROFILE
=
{
img
:
""
,
img
:
""
,
};
};
...
...
client/src/components/Room/ChannelList.js
View file @
8385db83
...
@@ -15,7 +15,7 @@ const ChannelList = () => {
...
@@ -15,7 +15,7 @@ const ChannelList = () => {
const
{
roomId
}
=
useParams
();
const
{
roomId
}
=
useParams
();
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
channel
,
setChannel
]
=
useState
([
INIT_CHANNEL
]);
const
[
channel
,
setChannel
]
=
useState
([
INIT_CHANNEL
]);
const
id
=
local
Storage
.
getItem
(
'
user
'
);
const
id
=
session
Storage
.
getItem
(
'
user
'
);
async
function
getChannel
(
roomId
)
{
async
function
getChannel
(
roomId
)
{
try
{
try
{
...
...
client/src/components/Room/ChannelSingle.js
View file @
8385db83
...
@@ -9,7 +9,7 @@ const ChannelSingle = (props) => {
...
@@ -9,7 +9,7 @@ const ChannelSingle = (props) => {
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
roomName
,
setRoomName
]
=
useState
(
''
);
const
[
roomName
,
setRoomName
]
=
useState
(
''
);
const
{
roomId
,
channelId
}
=
useParams
();
const
{
roomId
,
channelId
}
=
useParams
();
const
userId
=
local
Storage
.
getItem
(
'
user
'
)
const
userId
=
session
Storage
.
getItem
(
'
user
'
)
async
function
joinChannel
(
e
)
{
async
function
joinChannel
(
e
)
{
...
...
client/src/components/Room/RightHamburger.js
View file @
8385db83
...
@@ -5,6 +5,8 @@ import RoomApi from "../../apis/room.api";
...
@@ -5,6 +5,8 @@ import RoomApi from "../../apis/room.api";
import
catchErrors
from
"
../../context/catchError
"
;
import
catchErrors
from
"
../../context/catchError
"
;
import
KakaoShareButton
from
"
../KakaoShareButton
"
;
import
KakaoShareButton
from
"
../KakaoShareButton
"
;
import
Roomnamechange
from
"
./Roomnamechange
"
;
import
Roomnamechange
from
"
./Roomnamechange
"
;
import
userApi
from
"
../../apis/user.api
"
;
import
roomApi
from
"
../../apis/room.api
"
;
const
INIT_ROOM
=
{
const
INIT_ROOM
=
{
name
:
""
,
name
:
""
,
...
@@ -20,7 +22,7 @@ const RightHamburger = () => {
...
@@ -20,7 +22,7 @@ const RightHamburger = () => {
const
[
room
,
setRoom
]
=
useState
([
INIT_ROOM
]);
const
[
room
,
setRoom
]
=
useState
([
INIT_ROOM
]);
const
{
roomId
}
=
useParams
();
const
{
roomId
}
=
useParams
();
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
id
=
local
Storage
.
getItem
(
"
user
"
);
const
id
=
session
Storage
.
getItem
(
"
user
"
);
async
function
getRoom
(
roomId
)
{
async
function
getRoom
(
roomId
)
{
try
{
try
{
...
@@ -30,7 +32,6 @@ const RightHamburger = () => {
...
@@ -30,7 +32,6 @@ const RightHamburger = () => {
name
:
data
[
0
].
name
,
name
:
data
[
0
].
name
,
owner
:
data
[
0
].
owner
,
owner
:
data
[
0
].
owner
,
});
});
console
.
log
(
roomdata
);
setRoom
(
roomdata
);
setRoom
(
roomdata
);
}
catch
(
error
)
{
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
catchErrors
(
error
,
setError
);
...
@@ -38,9 +39,12 @@ const RightHamburger = () => {
...
@@ -38,9 +39,12 @@ const RightHamburger = () => {
}
}
async
function
exitRoom
()
{
async
function
exitRoom
()
{
console
.
log
(
"
id, roomid정보
"
,
id
,
roomId
);
try
{
try
{
const
data
=
await
RoomApi
.
exitRoom
({
id
,
roomId
});
const
data
=
await
RoomApi
.
exitRoom
({
id
,
roomId
});
if
(
data
.
owner
===
Number
(
id
)){
const
room
=
await
RoomApi
.
removeRoom
({
roomId
:
roomId
})
console
.
log
(
room
)
}
}
catch
(
error
)
{
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
catchErrors
(
error
,
setError
);
}
}
...
@@ -65,6 +69,38 @@ const RightHamburger = () => {
...
@@ -65,6 +69,38 @@ const RightHamburger = () => {
catchErrors
(
error
,
setError
);
catchErrors
(
error
,
setError
);
}
}
}
}
async
function
exitChannel
()
{
try
{
const
data
=
await
userApi
.
getUser
(
id
);
const
A
=
doubleJoinCheck
(
data
.
name
);
if
(
A
)
{
await
roomApi
.
doubleJoin
({
roomId
:
roomId
,
index1
:
A
.
index1
,
index2
:
A
.
index2
,
joinChName
:
A
.
joinChName
,
});
}
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
}
function
doubleJoinCheck
(
e
)
{
for
(
const
index
in
channel
)
{
for
(
const
el
in
channel
[
index
].
joinUser
)
{
if
(
channel
[
index
].
joinUser
[
el
]
===
e
)
{
const
doublejoinCh
=
channel
[
index
].
channelName
;
const
A
=
{
index1
:
index
,
index2
:
el
,
joinChName
:
doublejoinCh
,
};
return
A
;
}
}
}
}
// console.log(channel)
// console.log(channel)
...
@@ -289,6 +325,7 @@ const RightHamburger = () => {
...
@@ -289,6 +325,7 @@ const RightHamburger = () => {
<
button
<
button
type
=
"
button
"
type
=
"
button
"
onClick
=
{
exitRoom
}
onClick
=
{
exitRoom
}
onSubmit
=
{
exitChannel
}
className
=
"
btn btn-primary
"
className
=
"
btn btn-primary
"
data
-
bs
-
dismiss
=
"
modal
"
data
-
bs
-
dismiss
=
"
modal
"
>
>
...
...
client/src/context/auth.js
View file @
8385db83
import
axios
from
'
axios
'
import
axios
from
'
axios
'
export
function
handleLogin
(
userId
)
{
export
function
handleLogin
(
userId
)
{
local
Storage
.
setItem
(
"
user
"
,
userId
)
session
Storage
.
setItem
(
"
user
"
,
userId
)
}
}
export
async
function
handleLogout
()
{
export
async
function
handleLogout
()
{
alert
(
"
로그아웃되었습니다.
"
)
alert
(
"
로그아웃되었습니다.
"
)
local
Storage
.
removeItem
(
"
user
"
)
session
Storage
.
removeItem
(
"
user
"
)
await
axios
.
get
(
'
/api/auth/logout
'
)
await
axios
.
get
(
'
/api/auth/logout
'
)
window
.
location
.
href
=
'
/
'
window
.
location
.
href
=
'
/
'
}
}
export
function
isAuthenticated
()
{
export
function
isAuthenticated
()
{
const
userId
=
local
Storage
.
getItem
(
'
loginStatus
'
)
const
userId
=
session
Storage
.
getItem
(
'
loginStatus
'
)
if
(
userId
)
{
if
(
userId
)
{
return
userId
return
userId
}
else
{
}
else
{
...
...
client/src/context/auth_context.js
View file @
8385db83
...
@@ -36,7 +36,7 @@ const AuthProvider = ({ children }) => {
...
@@ -36,7 +36,7 @@ const AuthProvider = ({ children }) => {
setError
(
""
);
setError
(
""
);
setLoading
(
true
);
setLoading
(
true
);
const
user
=
await
authApi
.
login
(
email
,
password
);
const
user
=
await
authApi
.
login
(
email
,
password
);
local
Storage
.
setItem
(
config
.
loginUser
,
JSON
.
stringify
(
user
));
session
Storage
.
setItem
(
config
.
loginUser
,
JSON
.
stringify
(
user
));
setUser
(
user
);
setUser
(
user
);
return
true
;
return
true
;
...
@@ -53,7 +53,7 @@ const AuthProvider = ({ children }) => {
...
@@ -53,7 +53,7 @@ const AuthProvider = ({ children }) => {
setError
(
""
);
setError
(
""
);
setUser
(
null
);
setUser
(
null
);
alert
(
"
로그아웃되었습니다.
"
);
alert
(
"
로그아웃되었습니다.
"
);
local
Storage
.
removeItem
(
config
.
loginUser
);
session
Storage
.
removeItem
(
config
.
loginUser
);
setLoading
(
true
);
setLoading
(
true
);
await
axios
.
get
(
`
${
baseUrl
}
/api/auth/logout`
);
await
axios
.
get
(
`
${
baseUrl
}
/api/auth/logout`
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
client/src/pages/InvitePage.js
View file @
8385db83
import
Header
from
"
../components/Header
"
;
import
Header
from
"
../components/Header
"
;
const
InvitePage
=
()
=>
{
const
InvitePage
=
()
=>
{
const
usercheck
=
local
Storage
.
getItem
(
"
user
"
);
const
usercheck
=
session
Storage
.
getItem
(
"
user
"
);
function
goInvitedroom
()
{
function
goInvitedroom
()
{
let
check1
=
null
;
let
check1
=
null
;
...
...
server/controllers/room.controller.js
View file @
8385db83
...
@@ -13,13 +13,10 @@ const joinRoom = async (req, res) => {
...
@@ -13,13 +13,10 @@ const joinRoom = async (req, res) => {
//roomId에 일치하는 방의 member정보에 userId 저장하기
//roomId에 일치하는 방의 member정보에 userId 저장하기
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
const
includeUserId
=
room_Id
.
member
.
includes
(
parseInt
(
userId
));
const
includeUserId
=
room_Id
.
member
.
includes
(
parseInt
(
userId
));
// console.log('Include확인:',includeUserId)
if
(
!
includeUserId
)
{
if
(
!
includeUserId
)
{
//아직 참여되지 않은 방인경우
//아직 참여되지 않은 방인경우
room_Id
.
member
.
push
(
userId
);
//member에 userId추가
room_Id
.
member
.
push
(
userId
);
//member에 userId추가
// 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
}
});
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
const
user_Id
=
await
User
.
findOne
({
where
:
{
id
:
userId
}
});
if
(
Boolean
(
user_Id
.
roomNumber
))
{
if
(
Boolean
(
user_Id
.
roomNumber
))
{
...
@@ -29,7 +26,6 @@ const joinRoom = async (req, res) => {
...
@@ -29,7 +26,6 @@ const joinRoom = async (req, res) => {
//첫 roomNumber인 경우
//첫 roomNumber인 경우
user_Id
.
roomNumber
=
[
roomId
];
user_Id
.
roomNumber
=
[
roomId
];
}
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await
User
.
update
(
await
User
.
update
(
{
roomNumber
:
user_Id
.
roomNumber
},
{
roomNumber
:
user_Id
.
roomNumber
},
{
where
:
{
id
:
userId
}
}
{
where
:
{
id
:
userId
}
}
...
@@ -54,7 +50,6 @@ const createRoom = async (req, res) => {
...
@@ -54,7 +50,6 @@ const createRoom = async (req, res) => {
const
img
=
avatar
.
filename
;
const
img
=
avatar
.
filename
;
const
id
=
nanoid
();
const
id
=
nanoid
();
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
// console.log('id:', id)
while
(
Id
)
{
while
(
Id
)
{
const
id
=
nanoid
();
const
id
=
nanoid
();
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
const
Id
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
...
@@ -71,7 +66,6 @@ const createRoom = async (req, res) => {
...
@@ -71,7 +66,6 @@ const createRoom = async (req, res) => {
member
:
[
userId
],
member
:
[
userId
],
profileimg
:
img
,
profileimg
:
img
,
};
};
// console.log('newRoom:', newRoom)
await
Room
.
create
(
newRoom
);
await
Room
.
create
(
newRoom
);
//user.roomNumber에 id추가
//user.roomNumber에 id추가
...
@@ -83,7 +77,6 @@ const createRoom = async (req, res) => {
...
@@ -83,7 +77,6 @@ const createRoom = async (req, res) => {
//첫 roomNumber인 경우
//첫 roomNumber인 경우
user_Id
.
roomNumber
=
[
id
];
user_Id
.
roomNumber
=
[
id
];
}
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await
User
.
update
(
await
User
.
update
(
{
roomNumber
:
user_Id
.
roomNumber
},
{
roomNumber
:
user_Id
.
roomNumber
},
{
where
:
{
id
:
userId
}
}
{
where
:
{
id
:
userId
}
}
...
@@ -96,62 +89,78 @@ const createRoom = async (req, res) => {
...
@@ -96,62 +89,78 @@ const createRoom = async (req, res) => {
};
};
const
getRoom
=
async
(
req
,
res
)
=>
{
const
getRoom
=
async
(
req
,
res
)
=>
{
// console.log("fhgfghdgfdgf:", req.body);
try
{
try
{
const
roomlist
=
await
Room
.
findAll
({
where
:
{
id
:
req
.
body
}
});
const
roomlist
=
await
Room
.
findAll
({
where
:
{
id
:
req
.
body
}
});
// console.log(roomlist);
res
.
json
(
roomlist
);
res
.
json
(
roomlist
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
status
(
500
).
send
(
"
에러
"
);
res
.
status
(
500
).
send
(
"
에러
"
);
}
}
};
};
const
exitRoom
=
async
(
req
,
res
)
=>
{
const
exitRoom
=
async
(
req
,
res
)
=>
{
const
{
id
,
roomId
}
=
req
.
params
;
const
{
id
,
roomId
}
=
req
.
params
;
console
.
log
(
id
,
roomId
);
try
{
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
console
.
log
(
room
.
member
);
const
index
=
room
.
member
.
indexOf
(
id
);
const
index
=
room
.
member
.
indexOf
(
id
);
room
.
member
.
splice
(
index
,
1
);
console
.
log
(
"
index
"
,
index
);
const
newRoom
=
await
Room
.
update
(
room
.
member
.
splice
(
index
,
1
);
{
member
:
room
.
member
},
await
Room
.
update
({
member
:
room
.
member
},
{
where
:
{
id
:
roomId
}
});
{
where
:
{
id
:
roomId
}
}
);
const
user
=
await
User
.
findOne
({
where
:
{
id
:
id
}
});
const
user
=
await
User
.
findOne
({
where
:
{
id
:
id
}
});
console
.
log
(
user
.
roomNumber
);
const
index2
=
user
.
roomNumber
.
indexOf
(
id
);
const
index2
=
user
.
roomNumber
.
indexOf
(
id
);
user
.
roomNumber
.
splice
(
index2
,
1
);
console
.
log
(
"
index
"
,
index2
);
const
newUser
=
await
User
.
update
(
user
.
roomNumber
.
splice
(
index2
,
1
);
{
roomNumber
:
user
.
roomNumber
},
await
User
.
update
({
roomNumber
:
user
.
roomNumber
},
{
where
:
{
id
:
id
}
});
{
where
:
{
id
:
id
}
}
);
return
res
.
json
(
room
);
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
"
에러
"
);
}
};
};
const
changename
=
async
(
req
,
res
)
=>
{
const
changename
=
async
(
req
,
res
)
=>
{
const
{
id
,
name
}
=
req
.
body
;
const
{
id
,
name
}
=
req
.
body
;
console
.
log
(
req
.
body
);
try
{
try
{
await
Room
.
update
({
name
:
name
},
{
where
:
{
id
:
id
}
});
await
Room
.
update
({
name
:
name
},
{
where
:
{
id
:
id
}
});
const
room1
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
const
room1
=
await
Room
.
findOne
({
where
:
{
id
:
id
}
});
console
.
log
(
"
Room:
"
,
room1
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
status
(
500
).
send
(
"
에러
"
);
res
.
status
(
500
).
send
(
"
에러
"
);
}
}
};
};
const
joinChannel
=
async
(
req
,
res
)
=>
{
const
joinChannel
=
async
(
req
,
res
)
=>
{
const
{
roomId
,
channelName
,
plusUser
,
index
}
=
req
.
body
;
const
{
roomId
,
channelName
,
plusUser
,
index
}
=
req
.
body
;
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
try
{
room
.
channel
[
index
][
channelName
].
push
(
plusUser
);
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
room
.
channel
[
index
][
channelName
].
push
(
plusUser
);
return
res
.
json
(
true
);
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
"
error
"
);
}
};
};
const
doubleJoin
=
async
(
req
,
res
)
=>
{
const
doubleJoin
=
async
(
req
,
res
)
=>
{
const
{
roomId
,
index1
,
index2
,
joinChName
}
=
req
.
body
;
const
{
roomId
,
index1
,
index2
,
joinChName
}
=
req
.
body
;
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
try
{
room
.
channel
[
index1
][
joinChName
].
splice
(
index2
,
1
);
const
room
=
await
Room
.
findOne
({
where
:
{
id
:
roomId
}
});
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
room
.
channel
[
index1
][
joinChName
].
splice
(
index2
,
1
);
return
res
.
json
(
true
);
await
Room
.
update
({
channel
:
room
.
channel
},
{
where
:
{
id
:
roomId
}
});
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
"
error
"
);
}
};
const
removeRoom
=
async
(
req
,
res
)
=>
{
const
{
roomId
}
=
req
.
params
;
console
.
log
(
'
서버연결성공!!!!
'
,
roomId
)
try
{
const
room
=
await
Room
.
destroy
({
where
:
{
id
:
roomId
}
});
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
"
error
"
);
}
};
};
// const makeChannel = async (req, res) => {
// const makeChannel = async (req, res) => {
...
@@ -168,4 +177,5 @@ export default {
...
@@ -168,4 +177,5 @@ export default {
changename
,
changename
,
joinChannel
,
joinChannel
,
doubleJoin
,
doubleJoin
,
removeRoom
,
};
};
server/routes/room.route.js
View file @
8385db83
...
@@ -9,6 +9,7 @@ router.route("/join").put(roomCrtl.joinRoom);
...
@@ -9,6 +9,7 @@ router.route("/join").put(roomCrtl.joinRoom);
router
.
route
(
"
/changename
"
).
put
(
roomCrtl
.
changename
);
router
.
route
(
"
/changename
"
).
put
(
roomCrtl
.
changename
);
router
.
route
(
"
/joinChannel
"
).
post
(
roomCrtl
.
joinChannel
);
router
.
route
(
"
/joinChannel
"
).
post
(
roomCrtl
.
joinChannel
);
router
.
route
(
"
/doubleJoin
"
).
post
(
roomCrtl
.
doubleJoin
);
router
.
route
(
"
/doubleJoin
"
).
post
(
roomCrtl
.
doubleJoin
);
router
.
route
(
"
/removeRoom/:roomId
"
).
delete
(
roomCrtl
.
removeRoom
);
// router.route("/makeChannel").post(roomCrtl.makeChannel);
// router.route("/makeChannel").post(roomCrtl.makeChannel);
export
default
router
;
export
default
router
;
\ No newline at end of file
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