Commit a139def2 authored by 우지원's avatar 우지원
Browse files

Merge remote-tracking branch 'origin/jaeyeon2854' into woojiweon2

parents 90defe36 ef4c3577
...@@ -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;
...@@ -27,7 +27,6 @@ const CreateRoom = () => { ...@@ -27,7 +27,6 @@ const CreateRoom = () => {
} else { } else {
setRoom({ ...room, [name]: value }) setRoom({ ...room, [name]: value })
} }
console.log(room)
} }
async function handleSubmit(e) { async function handleSubmit(e) {
......
...@@ -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
......
...@@ -13,7 +13,6 @@ const ChannelSingle = (props) => { ...@@ -13,7 +13,6 @@ const ChannelSingle = (props) => {
async function joinChannel(e) { async function joinChannel(e) {
console.log(e, userId)
try { try {
const data = await userApi.getUser(userId); const data = await userApi.getUser(userId);
const index1 = indexCheck(e) const index1 = indexCheck(e)
......
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { Link, useParams } from "react-router-dom"; import { Link, useParams } from "react-router-dom";
import ChannelSingle from "./ChannelSingle"; import ChannelSingle from "./ChannelSingle";
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 userApi from "../../apis/user.api";
import roomApi from "../../apis/room.api";
const INIT_ROOM = { const INIT_ROOM = {
name: "", name: "",
...@@ -25,13 +25,12 @@ const RightHamburger = () => { ...@@ -25,13 +25,12 @@ const RightHamburger = () => {
async function getRoom(roomId) { async function getRoom(roomId) {
try { try {
const data = await RoomApi.getRoom([roomId]); const data = await roomApi.getRoom([roomId]);
const roomdata = []; const roomdata = [];
roomdata.push({ roomdata.push({
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);
...@@ -39,9 +38,12 @@ const RightHamburger = () => { ...@@ -39,9 +38,12 @@ const RightHamburger = () => {
} }
async function exitRoom() { async function exitRoom() {
console.log("id, roomid정보", id, roomId);
try { try {
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);
} }
...@@ -49,7 +51,7 @@ const RightHamburger = () => { ...@@ -49,7 +51,7 @@ const RightHamburger = () => {
async function getChannel(roomId) { async function getChannel(roomId) {
try { try {
const data = await RoomApi.getRoom([roomId]); const data = await roomApi.getRoom([roomId]);
const Channel = data[0].channel; const Channel = data[0].channel;
const channelList = []; const channelList = [];
for (const prop in Channel) { for (const prop in Channel) {
...@@ -66,13 +68,45 @@ const RightHamburger = () => { ...@@ -66,13 +68,45 @@ 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;
}
}
}
}
async function exitChannel() { async function exitChannel() {
try { try {
const data = await UserApi.getUser(id); const data = await userApi.getUser(id);
const A = doubleJoinCheck(data.name) const A = doubleJoinCheck(data.name)
if (A) { if (A) {
await RoomApi.doubleJoin({ roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName }) await roomApi.doubleJoin({ roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName })
} }
} catch (error) { } catch (error) {
catchErrors(error, setError); catchErrors(error, setError);
...@@ -317,7 +351,8 @@ const RightHamburger = () => { ...@@ -317,7 +351,8 @@ const RightHamburger = () => {
> >
<button <button
type="button" type="button"
onClick={exitRoom, exitChannel} onClick={exitRoom}
onSubmit={exitChannel}
className="btn btn-primary" className="btn btn-primary"
data-bs-dismiss="modal" data-bs-dismiss="modal"
> >
......
...@@ -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(userId); const includeUserId = room_Id.member.includes(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,81 @@ const createRoom = async (req, res) => { ...@@ -96,62 +89,81 @@ 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);
console.log("index", index);
room.member.splice(index, 1); room.member.splice(index, 1);
await Room.update({ member: room.member }, { where: { id: roomId } }); const newRoom = await Room.update(
{ member: room.member },
{ 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);
console.log("index", index2);
user.roomNumber.splice(index2, 1); user.roomNumber.splice(index2, 1);
await User.update({ roomNumber: user.roomNumber }, { where: { id: id } }); const newUser = await User.update(
{ roomNumber: user.roomNumber },
{ 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); return res.body.json(true)
} 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;
try {
const room = await Room.findOne({ where: { id: roomId } }); const room = await Room.findOne({ where: { id: roomId } });
room.channel[index][channelName].push(plusUser); room.channel[index][channelName].push(plusUser);
await Room.update({ channel: room.channel }, { where: { id: roomId } }); await Room.update({ channel: room.channel }, { where: { id: roomId } });
return res.json(true); return res.json(true)
} 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;
try {
const room = await Room.findOne({ where: { id: roomId } }); const room = await Room.findOne({ where: { id: roomId } });
room.channel[index1][joinChName].splice(index2, 1); room.channel[index1][joinChName].splice(index2, 1);
await Room.update({ channel: room.channel }, { where: { id: roomId } }); await Room.update({ channel: room.channel }, { where: { id: roomId } });
return res.json(true); return res.json(true)
} 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 +180,5 @@ export default { ...@@ -168,4 +180,5 @@ export default {
changename, changename,
joinChannel, joinChannel,
doubleJoin, doubleJoin,
removeRoom,
}; };
...@@ -24,7 +24,7 @@ const RoomModel = (sequelize) => { ...@@ -24,7 +24,7 @@ const RoomModel = (sequelize) => {
}, },
channel: { channel: {
type: DataTypes.ARRAY(DataTypes.JSON), type: DataTypes.ARRAY(DataTypes.JSON),
defaultValue: [{"회의": ["지원", "재연"]}, {"사담": ["지원", "재연", "서연"]}], defaultValue: [{"회의": []}, {"일반": []}],
}, },
}, },
{ timestamps: true } { timestamps: true }
......
...@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment