roomEnter.controller.js 666 Bytes
Newer Older
Soo Hyun Kim's avatar
Soo Hyun Kim committed
1
2
3
import Room from "../models/Room.js"

const roomEnter = async (req, res) => {
Soo Hyun Kim's avatar
Soo Hyun Kim committed
4
5
    const roomId = req.body.enterCode
    // console.log(req)
Soo Hyun Kim's avatar
Soo Hyun Kim committed
6
7
8
9
10
11

    try {
        const room = await Room.findOne({ roomId })
        if (!room) {
            return res.status(404).send(`참여코드가 존재하지 않습니다.`)
        }
Soo Hyun Kim's avatar
Soo Hyun Kim committed
12
13
14
15
16
17

        console.log('roomId존재')

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

Soo Hyun Kim's avatar
Soo Hyun Kim committed
18
19
20
    } catch (error) {
        //알수없는 모든 에러발생시 처리
        console.log(error)
Soo Hyun Kim's avatar
Soo Hyun Kim committed
21
        res.status(500).send('방 참여 에러')
Soo Hyun Kim's avatar
Soo Hyun Kim committed
22
23
24
25
    }
}

export default { roomEnter }