diff --git a/client/src/apis/room.api.js b/client/src/apis/room.api.js index 11d018fe0d92cd28d473f3772e761abff543f0f6..c2e02f095b00542a5f9f9591ae08cc2eec4f65c0 100644 --- a/client/src/apis/room.api.js +++ b/client/src/apis/room.api.js @@ -25,11 +25,17 @@ const joinChannel = async (payload) => { return data; }; -const makeChannel = async (payload) => { - const { data } = await axios.post("/api/room/makeChannel", payload); +const doubleJoin = async (payload) => { + const { data } = await axios.post("/api/room/doubleJoin", payload); return data; }; -const roomApi = { getRoom, exitRoom, create, join, joinChannel, makeChannel }; + +// const makeChannel = async (payload) => { +// const { data } = await axios.post("/api/room/makeChannel", payload); +// return data; +// }; + +const roomApi = { getRoom, exitRoom, create, join, joinChannel, doubleJoin }; export default roomApi; diff --git a/client/src/components/Room/ChannelSingle.js b/client/src/components/Room/ChannelSingle.js index 33d780ee7c3747a94a8a2f63bd40827d938e3f12..6cf7caadae3a2e90d57d17820f1943eb150cf526 100644 --- a/client/src/components/Room/ChannelSingle.js +++ b/client/src/components/Room/ChannelSingle.js @@ -6,6 +6,7 @@ import catchErrors from "../../context/catchError"; const ChannelSingle = (props) => { const [error, setError] = useState(""); + const [userName, setUserName] = useState(''); const [success, setSuccess] = useState(false); const [roomName, setRoomName] = useState(''); const { roomId, channelId } = useParams(); @@ -18,15 +19,23 @@ const ChannelSingle = (props) => { console.log(e, userId) try { const data = await userApi.getUser(userId); - const el = indexCheck(e) - console.log(el) - const mem = props.channel[el].joinUser - console.log(mem) + setUserName(data.name) + const index1 = indexCheck(e) + const A = doubleJoinCheck(data.name) + console.log(A) + const mem = props.channel[index1].joinUser const joinCh = mem.includes(data.name); - console.log(joinCh) + console.log(A) if (!joinCh) { - const roomA = await roomApi.joinChannel({ roomId: roomId, channelName: e, plusUser: data.name, index: el }) - console.log(roomA) + if (A) { + console.log('더블더블') + console.log(A.index1, A.index2, A.joinChName) + // { roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName } + const double = await roomApi.doubleJoin({ roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName }) + console.log(double) + } + console.log('서버연결시작') + const roomA = await roomApi.joinChannel({ roomId: roomId, channelName: e, plusUser: data.name, index: index1 }) setRoomName(e) setSuccess(true) } else { @@ -40,12 +49,25 @@ const ChannelSingle = (props) => { console.log('정보들어왔나', roomName, success) function indexCheck(e) { - for (const el in props.channel) { - console.log('체크', props.channel[el].channelName, e) - console.log('체크', props.channel[el].channelName === e) - if (props.channel[el].channelName === e) { - console.log('el', el) - return el + for (const index1 in props.channel) { + if (props.channel[index1].channelName === e) { + return index1 + } + } + } + + function doubleJoinCheck(e) { + for (const index in props.channel) { + for (const el in props.channel[index].joinUser) { + if (props.channel[index].joinUser[el] === e) { + const doublejoinCh = props.channel[index].channelName + const A = { + index1: index, + index2: el, + joinChName: doublejoinCh, + } + return A + } } } } diff --git a/server/controllers/room.controller.js b/server/controllers/room.controller.js index 39f02d90d7cc6fe399bbf27fe71822f179f4c331..45bffb6dcb91997d2d4384127777f6c1019317ba 100644 --- a/server/controllers/room.controller.js +++ b/server/controllers/room.controller.js @@ -121,18 +121,33 @@ const exitRoom = async (req, res) => { const joinChannel = async (req, res) => { const { roomId, channelName, plusUser, index } = req.body + console.log('연결성공') const room = await Room.findOne({ where: { id: roomId } }); room.channel[index][channelName].push(plusUser) - console.log('확인2',room.channel[index]) + console.log('확인2', room.channel[index]) + console.log('확인2', room.channel) await Room.update({ channel: room.channel }, { where: { id: roomId } }); return res.json(true) } -const makeChannel = async (req, res) => { - const { roomId, channelName } = req.body - console.log(roomId, channelName) +const doubleJoin = async (req, res) => { + console.log('연결성공', req.body) + const { roomId, index1, index2, joinChName } = req.body + console.log(index1) + const room = await Room.findOne({ where: { id: roomId } }); + console.log(room.channel[index1][joinChName]) + room.channel[index1][joinChName].splice(index2, 1) + console.log(room.channel[index1][joinChName]) + console.log('room.channel', room.channel) + await Room.update({ channel: room.channel }, { where: { id: roomId } }); + return res.json(true) } +// const makeChannel = async (req, res) => { +// const { roomId, channelName } = req.body +// console.log(roomId, channelName) +// } + export default { - joinRoom, roomImgUpload, createRoom, getRoom, exitRoom, joinChannel, makeChannel, + joinRoom, roomImgUpload, createRoom, getRoom, exitRoom, joinChannel, doubleJoin, }; diff --git a/server/routes/room.route.js b/server/routes/room.route.js index 31f6c7404536db647d5f1d055f0f427883cb29ac..7390c0f8ff8a8e9ae5b5c1233d82e42a1825f198 100644 --- a/server/routes/room.route.js +++ b/server/routes/room.route.js @@ -7,6 +7,7 @@ router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom); router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom); router.route("/join").put(roomCrtl.joinRoom); router.route("/joinChannel").post(roomCrtl.joinChannel); -router.route("/makeChannel").post(roomCrtl.makeChannel); +router.route("/doubleJoin").post(roomCrtl.doubleJoin); +// router.route("/makeChannel").post(roomCrtl.makeChannel); export default router; \ No newline at end of file