Commit 0560f339 authored by 우지원's avatar 우지원
Browse files

방참여까지 완료

parent dd642a51
......@@ -16,7 +16,7 @@ const HomeProfile = () => {
async function getUser(id) {
try {
// `/users/${userId}`랑 userId랑 같은지 확인
const User = await userApi.user(id)
const User = await userApi.getUser(id)
console.log(User)
setUser(User.data)
console.log(user)
......
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom'
import userApi from '../../apis/user.api';
const RoomSingle = () => {
const id = 1
const [room, setRoom] = useState('')
const id = localStorage.getItem('user');
const channelId = 1
async function getRoom(id) {
try {
const Room = await userApi.getUser(id)
setRoom(Room.data.roomNumber)
} catch (error) {
// catchErrors(error, setError)
}
}
useEffect(() => {
getRoom(id)
}, [id])
return (
<Link
to={`/room/${id}/${channelId}`}
......@@ -33,45 +51,6 @@ const RoomSingle = () => {
<div className="ms-auto mt-2"> 15/34 </div>
</div>
<div
className="d-flex mx-4 my-2 p-2"
style={{ backgroundColor: '#C4C4C4' }}
>
<div style={{ width: '37px', height: '37px' }}>
<img
src="BORA.png"
className="rounded-circle"
style={{ width: '37px', height: '37px' }}
/>
</div>
<div
className="mx-3 mt-2"
style={{ width: '250px', overflow: 'scroll', whiteSpace: 'nowrap' }}
>
데계 재미있는 수학과 데계데계데계 재미있는 수학과
</div>
<div className="ms-auto mt-2"> 15/34 </div>
</div>
<div
className="d-flex mx-4 my-2 p-2"
style={{ backgroundColor: '#C4C4C4' }}
>
<div style={{ width: '37px', height: '37px' }}>
<img
src="BORA.png"
className="rounded-circle"
style={{ width: '37px', height: '37px' }}
/>
</div>
<div
className="mx-3 mt-2"
style={{ width: '250px', overflow: 'scroll', whiteSpace: 'nowrap' }}
>
데계 재미있는 수학과 데계데계데계 재미있는 수학과
</div>
<div className="ms-auto mt-2"> 15/34 </div>
</div>
</Link>
)
}
......
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'
const nanoid = customAlphabet('1234567890abcdef', 10)
......@@ -10,43 +8,39 @@ const joinRoom = async (req, res) => {
console.log('req.body.value:', req.body)
const { userId, roomId } = req.body
const room_Id = await Room.findOne({ where: { id: roomId } });
console.log('room_Id1:', room_Id)
// 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)) {
if (Boolean(room_Id)) { //roomId에 일치하는 방이 존재할때
//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)
//member정보에 userId가 이미 저장되어 있는지 확인 -> 이미 참여된 방인지 확인
const includeUserId = room_Id.member.includes(parseInt(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 } })
const roomID = await Room.findOne({ where: { id: roomId } });
console.log('room_Id2:', roomID.member)
console.log('room_Id2:', roomID.member) //update됬는지 확인
//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:', user_Id)
console.log('user_Id.roomNumber1:', user_Id.roomNumber)
console.log('user_Id.roomNumber1:', Boolean(user_Id.roomNumber))
if (Boolean(user_Id.roomNumber)) {
console.log('user_Id.roomNumber2:', Boolean(user_Id.roomNumber))
if (Boolean(user_Id.roomNumber)) { //다른 roomNumber가 이미 들어가 있는 경우 roomId추가
user_Id.roomNumber.push(roomId)
}
else {
else { //첫 roomNumber인 경우
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('이미 참여된 방입니다.')
}
} else {
return res.status(422).send('참여코드와 일치하는 방이 존재하지 않습니다.')
}
......
......@@ -25,8 +25,8 @@ sequelize
await Room.create({
id: "1234567890",
name: "room",
owner: "8888",
member: ['8888'],
owner: 8888,
member: [8888],
profileimg: "C:\fakepath\스크린샷(1).png",
});
......
......@@ -12,7 +12,7 @@ const RoomModel = (sequelize) => {
type: DataTypes.STRING,
},
owner: {
type: DataTypes.STRING,
type: DataTypes.INTEGER,
},
member: {
type: DataTypes.ARRAY(DataTypes.INTEGER),
......
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