chat.controller.js 775 Bytes
Newer Older
Soo Hyun Kim's avatar
Soo Hyun Kim committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import chat from "../models/chat.js"
import isLength from 'validator/lib/isLength.js'

const makeChat = async (req, res) => {
    const {name, interest, isOpen} = req.body;
    // console.log('/bodyCheck', interest);
    try {
        if (!isLength(name, { min: 3, max: 10 })) {
            return res.status(422).json({message: 'Name must be 3-10 characters'})
        }
        const newChat = await new chat({
            name,
            interest,
            isOpen
        }).save()
        console.log(newChat)
        res.json(newChat)
    } catch (error) {
        console.log(error)
        res.status(500).json({message: 'User signup error'})
    }
}

const hello = (req, res) => {
    res.send('Hello from users controller')
}

export default { makeChat, hello }