import Room from "../models/Room.js"

const roomEnter = async (req, res) => {
    const roomId = req.body.enterCode
    // console.log(req)

    try {
        const room = await Room.findOne({ roomId })
        if (!room) {
            return res.status(404).send(`참여코드가 존재하지 않습니다.`)
        }

        console.log('roomId존재')

        const name = await Room.findOne({ roomId: roomId }).select('roomName')
        return res.json(name.roomName)

    } catch (error) {
        //알수없는 모든 에러발생시 처리
        console.log(error)
        res.status(500).send('방 참여 에러')
    }
}

export default { roomEnter }