Commit 0804ee25 authored by seoyeon's avatar seoyeon
Browse files

Merge remote-tracking branch 'origin/jiweon827' into seoyeon2

parents ac15b407 231fc9bd
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 (
......
import { Room, User } from "../models/index.js";
import { customAlphabet } from 'nanoid'
import { Op } from 'sequelize';
import config from "../config/app.config.js";
import isLength from 'validator/lib/isLength.js'
......@@ -8,82 +9,74 @@ 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) {
//roomId에 일치하는 방의 member정보에 userId 저장하기
console.log('room_Id1:', room_Id)
console.log('room_Id있는지:', Boolean(room_Id))
console.log('room_Id.member1:', room_Id.member)
if (Boolean(room_Id)) {
//roomId에 일치하는 방의 member정보에 userId 저장하기
const matchedUserId = room_Id.member.filter(memberId => memberId === userId)
console.log('matchedUserId:', matchedUserId)
// if (matchedUserId.length === 0) {
// room_Id.member.push(userId)
// }
// else {
// return res.status(422).send('이미 참여된 방입니다.')
// }
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)
//userId에 일치하는 사용자의 roomNumber에 roomId저장하기
const user_Id = await User.findOne({ where: { id: userId } });
console.log('user_Id:', user_Id)
const matchedRoomId = user_Id.roomNumber.filter(roomNum => roomNum === roomId)
console.log('matchedRoomId:',matchedRoomId)
console.log('matchedRoomId boo:',Boolean(matchedRoomId))
console.log('user_Id.roomNumber1:', user_Id.roomNumber)
console.log('user_Id.roomNumber1:', Boolean(user_Id.roomNumber))
if (Boolean(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 } })
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)
console.log('room정보:', id, name, owner, [member], profileimg)
res.json(newRoom)
} catch (error) {
console.log(error)
......
......@@ -2,7 +2,13 @@ import { User } from '../models/index.js'
import jwt from 'jsonwebtoken'
import config from '../config/app.config.js'
import isLength from 'validator/lib/isLength.js'
import bcrypt from 'bcryptjs'
import bcrypt from "bcryptjs";
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) => {
try {
......@@ -79,6 +85,7 @@ const logout = (req, res) => {
}
export default {
user,
login,
signup,
logout,
......
......@@ -25,10 +25,9 @@ sequelize
await Room.create({
id: "1234567890",
name: "room",
owner: [ '600112d16d09ac6b7892d900' ],
member: [ '600112d16d09ac6b7892d900' ],
owner: "8888",
member: ['8888'],
profileimg: "C:\fakepath\스크린샷(1).png",
channel: [ '회의' ],
});
app.listen(appConfig.port, () => {
......
......@@ -12,16 +12,19 @@ const RoomModel = (sequelize) => {
type: DataTypes.STRING,
},
owner: {
type: DataTypes.ARRAY(DataTypes.STRING),
type: DataTypes.STRING,
},
member: {
type: DataTypes.ARRAY(DataTypes.STRING),
type: DataTypes.ARRAY(DataTypes.INTEGER),
//type: DataTypes.STRING,
},
profileimg: {
type: DataTypes.STRING,
defaultValue: "/user.png"
},
channel: {
type: DataTypes.ARRAY(DataTypes.JSON),
defaultValue: [{'회의':""}],
},
},
{ timestamps: true }
......
......@@ -28,9 +28,9 @@ const UserModel = (sequelize) => {
type: DataTypes.STRING,
defaultValue: "/user.png"
},
// roomNumber: {
// type: DataTypes.ARRAY(DataTypes.STRING),
// },
roomNumber: {
type: DataTypes.ARRAY(DataTypes.STRING),
},
},
{ 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