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) => {
return data;
};
const removeRoom = async (ID)=>{
const { data } = await axios.delete(
`/api/room/removeRoom/${ID.roomId}`
);
return data;
}
// const makeChannel = async (payload) => {
// const { data } = await axios.post("/api/room/makeChannel", payload);
// return data;
......@@ -50,6 +57,7 @@ const roomApi = {
changename,
joinChannel,
doubleJoin,
removeRoom
};
export default roomApi;
......@@ -27,7 +27,6 @@ const CreateRoom = () => {
} else {
setRoom({ ...room, [name]: value })
}
console.log(room)
}
async function handleSubmit(e) {
......
......@@ -46,7 +46,7 @@ const Login = () => {
}
if (success) {
alert('로그인 되었습니다')
return <Redirect to={`/user/${id}`} />;
window.location.href=`/user/${id}`
}
const { email, password } = user
......
......@@ -13,7 +13,6 @@ const ChannelSingle = (props) => {
async function joinChannel(e) {
console.log(e, userId)
try {
const data = await userApi.getUser(userId);
const index1 = indexCheck(e)
......
import React, { useState, useEffect } from "react";
import { Link, useParams } from "react-router-dom";
import ChannelSingle from "./ChannelSingle";
import RoomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";
import KakaoShareButton from "../KakaoShareButton";
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 = {
name: "",
......@@ -25,13 +25,12 @@ const RightHamburger = () => {
async function getRoom(roomId) {
try {
const data = await RoomApi.getRoom([roomId]);
const data = await roomApi.getRoom([roomId]);
const roomdata = [];
roomdata.push({
name: data[0].name,
owner: data[0].owner,
});
console.log(roomdata);
setRoom(roomdata);
} catch (error) {
catchErrors(error, setError);
......@@ -39,9 +38,12 @@ const RightHamburger = () => {
}
async function exitRoom() {
console.log("id, roomid정보", id, roomId);
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) {
catchErrors(error, setError);
}
......@@ -49,7 +51,7 @@ const RightHamburger = () => {
async function getChannel(roomId) {
try {
const data = await RoomApi.getRoom([roomId]);
const data = await roomApi.getRoom([roomId]);
const Channel = data[0].channel;
const channelList = [];
for (const prop in Channel) {
......@@ -66,13 +68,45 @@ const RightHamburger = () => {
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() {
try {
const data = await UserApi.getUser(id);
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 })
await roomApi.doubleJoin({ roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName })
}
} catch (error) {
catchErrors(error, setError);
......@@ -317,7 +351,8 @@ const RightHamburger = () => {
>
<button
type="button"
onClick={exitRoom, exitChannel}
onClick={exitRoom}
onSubmit={exitChannel}
className="btn btn-primary"
data-bs-dismiss="modal"
>
......
......@@ -13,13 +13,10 @@ const joinRoom = async (req, res) => {
//roomId에 일치하는 방의 member정보에 userId 저장하기
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
const includeUserId = room_Id.member.includes(userId);
// console.log('Include확인:',includeUserId)
if (!includeUserId) {
//아직 참여되지 않은 방인경우
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 } });
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const user_Id = await User.findOne({ where: { id: userId } });
if (Boolean(user_Id.roomNumber)) {
......@@ -29,7 +26,6 @@ const joinRoom = async (req, res) => {
//첫 roomNumber인 경우
user_Id.roomNumber = [roomId];
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await User.update(
{ roomNumber: user_Id.roomNumber },
{ where: { id: userId } }
......@@ -54,7 +50,6 @@ const createRoom = async (req, res) => {
const img = avatar.filename;
const id = nanoid();
const Id = await Room.findOne({ where: { id: id } });
// console.log('id:', id)
while (Id) {
const id = nanoid();
const Id = await Room.findOne({ where: { id: id } });
......@@ -71,7 +66,6 @@ const createRoom = async (req, res) => {
member: [userId],
profileimg: img,
};
// console.log('newRoom:', newRoom)
await Room.create(newRoom);
//user.roomNumber에 id추가
......@@ -83,7 +77,6 @@ const createRoom = async (req, res) => {
//첫 roomNumber인 경우
user_Id.roomNumber = [id];
}
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await User.update(
{ roomNumber: user_Id.roomNumber },
{ where: { id: userId } }
......@@ -96,62 +89,81 @@ const createRoom = async (req, res) => {
};
const getRoom = async (req, res) => {
// console.log("fhgfghdgfdgf:", req.body);
try {
const roomlist = await Room.findAll({ where: { id: req.body } });
// console.log(roomlist);
res.json(roomlist);
} catch (error) {
console.log(error);
res.status(500).send("에러");
}
};
const exitRoom = async (req, res) => {
const { id, roomId } = req.params;
console.log(id, roomId);
try {
const room = await Room.findOne({ where: { id: roomId } });
console.log(room.member);
const index = room.member.indexOf(id);
console.log("index", index);
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 } });
console.log(user.roomNumber);
const index2 = user.roomNumber.indexOf(id);
console.log("index", index2);
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 { id, name } = req.body;
console.log(req.body);
try {
await Room.update({ name: name }, { where: { id: id } });
const room1 = await Room.findOne({ where: { id: id } });
console.log("Room:", room1);
return res.body.json(true)
} catch (error) {
console.log(error);
res.status(500).send("에러");
}
};
const joinChannel = async (req, res) => {
const { roomId, channelName, plusUser, index } = req.body;
try {
const room = await Room.findOne({ where: { id: roomId } });
room.channel[index][channelName].push(plusUser);
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 { roomId, index1, index2, joinChName } = req.body;
try {
const room = await Room.findOne({ where: { id: roomId } });
room.channel[index1][joinChName].splice(index2, 1);
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) => {
......@@ -168,4 +180,5 @@ export default {
changename,
joinChannel,
doubleJoin,
removeRoom,
};
......@@ -24,7 +24,7 @@ const RoomModel = (sequelize) => {
},
channel: {
type: DataTypes.ARRAY(DataTypes.JSON),
defaultValue: [{"회의": ["지원", "재연"]}, {"사담": ["지원", "재연", "서연"]}],
defaultValue: [{"회의": []}, {"일반": []}],
},
},
{ timestamps: true }
......
......@@ -9,6 +9,7 @@ router.route("/join").put(roomCrtl.joinRoom);
router.route("/changename").put(roomCrtl.changename);
router.route("/joinChannel").post(roomCrtl.joinChannel);
router.route("/doubleJoin").post(roomCrtl.doubleJoin);
router.route("/removeRoom/:roomId").delete(roomCrtl.removeRoom);
// router.route("/makeChannel").post(roomCrtl.makeChannel);
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