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

0726

parent 3963ae7c
import axios from "axios";
const getUser = async (payload) => {
const { data } = await axios.get("/api/user", payload);
return data;
};
const login = async (payload) => {
const { data } = await axios.post("/api/login", payload);
return data;
......@@ -10,6 +15,6 @@ const signup = async (payload) => {
return data;
};
const userApi = { login, signup };
const userApi = { getUser, login, signup };
export default userApi;
......@@ -45,6 +45,7 @@ const AddRoom = () => {
className="p-3"
data-bs-toggle="modal"
data-bs-target="#joinModal"
// data-bs-dismiss="modal"
style={{
display: "flex",
flexDirection: "column",
......@@ -73,6 +74,7 @@ const AddRoom = () => {
className="p-3"
data-bs-toggle="modal"
data-bs-target="#makeModal"
// data-bs-dismiss="modal"
style={{
display: "flex",
flexDirection: "column",
......
import { useEffect, useState } from "react";
import { Redirect } from "react-router-dom";
import roomApi from "../../apis/room.api";
const userId = localStorage.getItem('user');
console.log(userId)
const INIT_ROOM = {
name: '',
owner: userId,
member: userId,
profileimg: '',
channel: ['회의'],
}
const CreateRoom = () => {
......@@ -20,11 +22,6 @@ const CreateRoom = () => {
isRoom ? setDisabled(false) : setDisabled(true);
}, [room]);
// const userId = localStorage.getItem('user');
// setRoom({...room, owner: userId})
// setRoom({...room, member: userId})
function handleChange(event) {
console.log(room)
const { name, value } = event.target
......@@ -39,9 +36,9 @@ const CreateRoom = () => {
const res = await roomApi.create(room)
// console.log(res)
const Id = res.id
// console.log(Id)
//alert(`방참여코드는 ${Id}입니다`)
//setSuccess(true)
console.log(Id)
alert(`방참여코드는 ${Id}입니다`)
setSuccess(true)
} catch (error) {
// catchErrors(error, setError);
} finally {
......@@ -52,7 +49,7 @@ const CreateRoom = () => {
if (success) {
console.log('success', success)
alert('룸생성이 완료되었습니다!')
//return <Redirect to='/' />
return <Redirect to='/user' />
}
const { name, owner, member, profileimg } = room;
......
import { Link } from "react-router-dom";
import { useState, useEffect } from "react";
import userApi from "../../apis/user.api";
const INIT_USER = {
id: '',
name: '',
img: '',
}
const HomeProfile = () => {
const id = 1;
const [user, setUser] = useState(INIT_USER)
const id = localStorage.getItem('user');
async function getUser(id) {
try {
// `/users/${userId}`랑 userId랑 같은지 확인
const User = await userApi.user(id)
console.log(User)
setUser(User.data)
console.log(user)
} catch (error) {
// catchErrors(error, setError)
}
}
useEffect(() => {
getUser(id)
}, [id])
return (
<Link to={`/profile/${id}`} className="text-decoration-none text-dark">
<form className="flex-column align-items-center justify-content-center m-2">
<div className="d-flex justify-content-center">
<img
src="cherry.jpg"
// src="cherry.jpg"
className="rounded-circle"
style={{
width: "157px",
height: "157px",
}}
value={user.img}
/>
</div>
<h1 className="d-flex justify-content-center"> CHERRY </h1>
<h2 className="d-flex justify-content-center"> #0805 </h2>
<h1 className="d-flex justify-content-center"> {user.name} </h1>
<h2 className="d-flex justify-content-center"> #{user.id} </h2>
</form>
<div
style={{ backgroundColor: "#262626", width: "auto", height: "2px" }}
......
......@@ -26,9 +26,9 @@ const JoinRoom = () => {
try {
// setLoading(true);
// setError("");
console.log('userId:',userId)
console.log('roomId:',roomId)
const data = await roomApi.join({userId: userId, roomId: roomId});
console.log('userId:', userId)
console.log('roomId:', roomId)
const data = await roomApi.join({ userId: userId, roomId: roomId });
console.log(data);
setSuccess(true);
} catch (error) {
......@@ -38,6 +38,7 @@ const JoinRoom = () => {
}
}
if (success) {
return <Redirect to="/user" />;
}
return (
......
......@@ -8,82 +8,73 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
const joinRoom = async (req, res) => {
console.log('req.body.value:', req.body)
const { userId, roomId } = req.body
console.log('userId:', userId)
console.log('roomId:', roomId)
const room_Id = await Room.findOne({ where: { id: roomId } });
console.log('room_Id:', room_Id)
if (room_Id) {
console.log('room_Id1:', room_Id)
console.log('room_Id있는지:', Boolean(room_Id))
if (Boolean(room_Id)) {
//roomId에 일치하는 방의 member정보에 userId 저장하기
console.log('room_Id.member1:', room_Id.member)
room_Id.member.push(userId)
console.log('room_Id.member2:', room_Id.member)
await Room.update({ 'member': room_Id.member }, { where: { id: roomId } })
const roomID = await Room.findOne({ where: { id: roomId } });
console.log('room_Id2:', roomID.member)
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
// const user_Id = await User.findOne({ where: { id: userId } });
// console.log('user_Id:', user_Id)
// console.log('user_Id.roomNumber1:', user_Id.roomNumber)
// user_Id.roomNumber.push(roomId)
// console.log('user_Id.roomNumber2:', user_Id.roomNumber)
// await User.update({ 'roomNumber': roomId }, { where: { id: userId } })
// const userID = await User.findOne({ where: { id: userId } });
// console.log('user_Id2:', userID.roomNumber)
const userInter = await Room.findOne({
where: { id: roomId },
Include: { member: userId }
}).then(_ => console.log('userInter되었습니다!'));
//const userInter = await Room.findOne({ Include: [{ id: roomId}, {member: userId}] });
console.log('userInter:',userInter)
console.log('userId:',userId)
if (Boolean(userInter)) {
return res.status(422).send('이미 참여된 방입니다.')
}
else {
room_Id.member.push(userId)
console.log('room_Id.member2:', room_Id.member)
await Room.update({ 'member': room_Id.member }, { where: { id: roomId } })
const roomID = await Room.findOne({ where: { id: roomId } });
console.log('room_Id2:', roomID.member)
// }
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const user_Id = await User.findOne({ where: { id: userId } });
console.log('user_Id:', user_Id)
console.log('user_Id.roomNumber1:', user_Id.roomNumber)
if (user_Id.roomNumber) {
user_Id.roomNumber.push(roomId)
}
else {
user_Id.roomNumber = roomId
}
console.log('user_Id.roomNumber2:', [user_Id.roomNumber])
await User.update({ 'roomNumber': [user_Id.roomNumber] }, { where: { id: userId } })
// .then(_ => res.json(true))
// const userID = await User.findOne({ where: { id: userId } });
// console.log('user_Id2:', userID.roomNumber)
}
} else {
return res.status(422).send('참여코드와 일치하는 방이 존재하지 않습니다.')
}
};
// const changemember = async (req, res) => {
// const { userId, roomId } = req.body
// // console.log(roomId)
// let room = await Room.findOne({ roomId: roomId }).select('member')
// const isPresent = room.member.indexOf(userId)
// indexOf : userId가 몇번째 인덱스인지 찾기
// try {
// if (isPresent < 0) {
// const memberId = room.member.push(userId)
// await Room.updateOne({ 'roomId': roomId }, { 'member': room.member })
// // console.log('room.member 업데이트 완료')
// return res.json(true)
// }
// else {
// return res.json(false)
// }
// } catch (error) {
// res.status(500).send('멤버 업데이트 실패')
// }
// }
const createRoom = async (req, res) => {
console.log('룸정보', req.body)
const { name, owner, member, profileimg, channel } = req.body;
console.log('owner:', owner)
const { name, owner, member, profileimg } = req.body;
const id = nanoid()
console.log('id:', id)
const Id = await Room.findOne({ where: { id: id } });
console.log("Id중복확인:", Id)
while (Id) {
console.log('id:', id)
while (Boolean(Id)) {
const id = nanoid()
const Id = await Room.findOne({ where: { id: id } });
}
try {
if (!isLength(name, { min: 3, max: 20 })) {
console.log('방이름은 3-20자여야 합니다.')
return res.status(422).send('방이름은 3-20자여야 합니다.')
}
const newRoom = await Room.create({
const newRoom = {
id: id,
name: name,
owner: owner,
member: member,
member: [member],
profileimg: profileimg,
channel: channel,
}).then(_ => console.log('room정보:', id, name, owner, member, profileimg, channel))
}
console.log('newRoom:', newRoom)
await Room.create(newRoom).then(_ => console.log('room정보:', id, name, owner, [member], profileimg))
res.json(newRoom)
} catch (error) {
console.log(error)
......
......@@ -4,14 +4,10 @@ import config from "../config/app.config.js";
import isLength from 'validator/lib/isLength.js'
import bcrypt from "bcryptjs";
const test = async (req, res) => {
try {
console.log(req);
res.json("안녕");
} catch (error) {
console.log(error);
return res.status(500).send("test 중 에러");
}
const user = async (req, res) => {
console.log(req.body)
const user = await User.findAll({ where: { id: req.body } });
req.json(user)
};
const login = async (req, res) => {
......@@ -71,7 +67,7 @@ const signup = async (req, res) => {
}
}
export default {
test,
user,
login,
signup,
};
......@@ -25,8 +25,8 @@ sequelize
await Room.create({
id: "1234567890",
name: "room",
owner: [ '600112d16d09ac6b7892d900' ],
member: [ '600112d16d09ac6b7892d900' ],
owner: "600112d16d09ac6b7892d900",
member: ['600112d16d09ac6b7892d900'],
profileimg: "C:\fakepath\스크린샷(1).png",
channel: [ '회의' ],
});
......
......@@ -12,7 +12,7 @@ const RoomModel = (sequelize) => {
type: DataTypes.STRING,
},
owner: {
type: DataTypes.ARRAY(DataTypes.STRING),
type: DataTypes.STRING,
},
member: {
type: DataTypes.ARRAY(DataTypes.STRING),
......@@ -22,6 +22,7 @@ const RoomModel = (sequelize) => {
},
channel: {
type: DataTypes.ARRAY(DataTypes.JSON),
defaultValue: ['회의'],
},
},
{ timestamps: true }
......
......@@ -3,6 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
const router = express.Router();
router.route("/getUser").get(userCtrl.user);
router.route("/login").post(userCtrl.login);
router.route("/signup").post(userCtrl.signup);
......
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