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

0802

parent bdbf406c
...@@ -14,6 +14,7 @@ app.use(express.json()); ...@@ -14,6 +14,7 @@ app.use(express.json());
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true }));
app.use(cookieParser()); app.use(cookieParser());
app.use('/uploads', express.static('uploads')) app.use('/uploads', express.static('uploads'))
app.use('/roomUploads', express.static('roomUploads'))
app.use("/api", mainRouter); app.use("/api", mainRouter);
let receiverPCs = {}; let receiverPCs = {};
......
...@@ -5,8 +5,8 @@ const getRoom = async (id) => { ...@@ -5,8 +5,8 @@ const getRoom = async (id) => {
return data; return data;
}; };
const create = async (payload) => { const create = async (formData) => {
const { data } = await axios.post("/api/room/create", payload); const { data } = await axios.post("/api/room/create", formData);
return data; return data;
}; };
......
...@@ -2,6 +2,7 @@ import { Link } from 'react-router-dom' ...@@ -2,6 +2,7 @@ import { Link } from 'react-router-dom'
import { handleLogout } from '../context/auth' import { handleLogout } from '../context/auth'
const Header = () => { const Header = () => {
const id = localStorage.getItem('user');
return ( return (
<div> <div>
<form <form
...@@ -10,7 +11,7 @@ const Header = () => { ...@@ -10,7 +11,7 @@ const Header = () => {
> >
<div className="d-flex justify-content-end"> <div className="d-flex justify-content-end">
<div> <div>
<Link to="/user/:id"> <Link to={`/user/${id}`}>
<img src="/BORA.png" style={{ width: '160px' }} /> <img src="/BORA.png" style={{ width: '160px' }} />
</Link> </Link>
</div> </div>
......
...@@ -11,6 +11,7 @@ const AddRoom = () => { ...@@ -11,6 +11,7 @@ const AddRoom = () => {
className="py-1 px-2" className="py-1 px-2"
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#myModal" data-bs-target="#myModal"
// data-bs-dismiss="modal"
style={{ style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
...@@ -72,6 +73,7 @@ const AddRoom = () => { ...@@ -72,6 +73,7 @@ const AddRoom = () => {
className="p-3" className="p-3"
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#makeModal" data-bs-target="#makeModal"
// data-bs-dismiss="modal"
style={{ style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
......
...@@ -38,7 +38,8 @@ const JoinRoom = () => { ...@@ -38,7 +38,8 @@ const JoinRoom = () => {
if (success) { if (success) {
// console.log('success', success) // console.log('success', success)
alert('룸참여가 완료되었습니다!') alert('룸참여가 완료되었습니다!')
return <Redirect to={`/user/${id}`} />; window.location.href=`/user/${id}`
// return <Redirect to={`/user/${id}`} />;
} }
return ( return (
...@@ -56,6 +57,7 @@ const JoinRoom = () => { ...@@ -56,6 +57,7 @@ const JoinRoom = () => {
></button> ></button>
</div> </div>
<div className="modal-body"> <div className="modal-body">
{error && <div className="alert alert-danger">{error}</div>}
<div className="input-group mb-3"> <div className="input-group mb-3">
<input <input
type="text" type="text"
...@@ -69,7 +71,9 @@ const JoinRoom = () => { ...@@ -69,7 +71,9 @@ const JoinRoom = () => {
/> />
</div> </div>
<div className="modal-footer"> <div className="modal-footer">
<button type="submit" className="btn btn-primary"> <button
type="submit"
className="btn btn-primary">
확인 확인
</button> </button>
</div> </div>
......
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Redirect } from 'react-router-dom' import { Redirect} from 'react-router-dom'
import userApi from '../apis/user.api' import userApi from '../apis/user.api'
import catchErrors from "../context/catchError"; import catchErrors from "../context/catchError";
import { handleLogin } from '../context/auth'; import { handleLogin } from '../context/auth';
const INIT_USER = { const INIT_USER = {
userId: '9999',
email: '', email: '',
password: '', password: '',
} }
......
...@@ -34,6 +34,7 @@ const InfoUpdate = () => { ...@@ -34,6 +34,7 @@ const InfoUpdate = () => {
const handleChange = async (event) => { const handleChange = async (event) => {
const { files } = event.target; const { files } = event.target;
console.log('files:',files)
let formData = new FormData(); let formData = new FormData();
formData.append("img", files[0]); formData.append("img", files[0]);
formData.append("id", userprofile); formData.append("id", userprofile);
......
...@@ -4,12 +4,14 @@ import LeftHamburger from './LeftHamburger'; ...@@ -4,12 +4,14 @@ import LeftHamburger from './LeftHamburger';
import RightHamburger from './RightHamburger'; import RightHamburger from './RightHamburger';
const ChannelList = () => { const ChannelList = () => {
const id = localStorage.getItem('user');
return ( return (
<div> <div>
<nav className="navbar navbar-light d-flex justify-content-between"> <nav className="navbar navbar-light d-flex justify-content-between">
<LeftHamburger /> <LeftHamburger />
<div> <div>
<Link to="/user/:id"> <Link to={`/user/${id}`}>
<img src="/BORA.png" style={{ width: '160px' }} /> <img src="/BORA.png" style={{ width: '160px' }} />
</Link> </Link>
</div> </div>
......
...@@ -35,13 +35,18 @@ const joinRoom = async (req, res) => { ...@@ -35,13 +35,18 @@ const joinRoom = async (req, res) => {
} }
}; };
const multer = require("multer");
const upLoadRoomImg = multer({ dest: "roomUploads/" });
const roomImgUpload = upLoadRoomImg.fields([{ name: "profileimg", maxCount: 1 }]);
const createRoom = async (req, res) => { const createRoom = async (req, res) => {
// console.log('룸정보', req.body) const { userId, name } = req.body;
const { name, owner, member, profileimg } = req.body; const avatar = req.files["profileimg"][0];
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) // console.log('id:', id)
while (Boolean(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 } });
} }
...@@ -53,23 +58,23 @@ const createRoom = async (req, res) => { ...@@ -53,23 +58,23 @@ const createRoom = async (req, res) => {
const newRoom = { const newRoom = {
id: id, id: id,
name: name, name: name,
owner: owner, owner: userId,
member: [member], member: [userId],
profileimg: profileimg, profileimg: img,
} }
// console.log('newRoom:', newRoom) // console.log('newRoom:', newRoom)
await Room.create(newRoom) await Room.create(newRoom)
//user.roomNumber에 id추가 //user.roomNumber에 id추가
const user_Id = await User.findOne({ where: { id: owner } }); const user_Id = await User.findOne({ where: { id: userId } });
if (Boolean(user_Id.roomNumber)) { //다른 roomNumber가 이미 들어가 있는 경우 id추가 if (user_Id.roomNumber) { //다른 roomNumber가 이미 들어가 있는 경우 id추가
user_Id.roomNumber.push(id) user_Id.roomNumber.push(id)
} }
else { //첫 roomNumber인 경우 else { //첫 roomNumber인 경우
user_Id.roomNumber = [id] user_Id.roomNumber = [id]
} }
// console.log('user_Id.roomNumber2:', user_Id.roomNumber) // console.log('user_Id.roomNumber2:', user_Id.roomNumber)
await User.update({ 'roomNumber': user_Id.roomNumber }, { where: { id: owner } }) await User.update({ 'roomNumber': user_Id.roomNumber }, { where: { id: userId } })
res.json(newRoom) res.json(newRoom)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
...@@ -82,5 +87,5 @@ const getRoom = async (req, res) => { ...@@ -82,5 +87,5 @@ const getRoom = async (req, res) => {
} }
export default { export default {
joinRoom, createRoom, getRoom joinRoom, roomImgUpload, createRoom, getRoom
}; };
...@@ -28,7 +28,7 @@ sequelize ...@@ -28,7 +28,7 @@ sequelize
name: "room", name: "room",
owner: 8888, owner: 8888,
member: [8888,9999], member: [8888,9999],
profileimg: "C:\fakepath\스크린샷(1).png", profileimg: "ef0930f6be18ce73380d952337a6de1f",
}); });
await Room.create({ await Room.create({
...@@ -36,7 +36,7 @@ sequelize ...@@ -36,7 +36,7 @@ sequelize
name: "room1", name: "room1",
owner: 9999, owner: 9999,
member: [9999], member: [9999],
profileimg: "C:\fakepath\스크린샷(1).png", profileimg: "ef0930f6be18ce73380d952337a6de1f",
}); });
app.listen(appConfig.port, () => { app.listen(appConfig.port, () => {
......
...@@ -20,7 +20,7 @@ const RoomModel = (sequelize) => { ...@@ -20,7 +20,7 @@ const RoomModel = (sequelize) => {
}, },
profileimg: { profileimg: {
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: "/user.png" defaultValue:'defaultimg'
}, },
channel: { channel: {
type: DataTypes.ARRAY(DataTypes.JSON), type: DataTypes.ARRAY(DataTypes.JSON),
......
...@@ -3,7 +3,7 @@ import roomCrtl from "../controllers/room.controller.js"; ...@@ -3,7 +3,7 @@ import roomCrtl from "../controllers/room.controller.js";
const router = express.Router(); const router = express.Router();
router.route("/getRoom").post(roomCrtl.getRoom); router.route("/getRoom").post(roomCrtl.getRoom);
router.route("/create").post(roomCrtl.createRoom); router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom);
router.route("/join").put(roomCrtl.joinRoom); router.route("/join").put(roomCrtl.joinRoom);
export default router; export default router;
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