user.controller.js 970 Bytes
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import User from "../models/User.js";
이재연's avatar
이재연 committed
2
import isLength from 'validator/lib/isLength.js'
Kim, Subin's avatar
Kim, Subin committed
3
4

const signup = async (req, res) => {
이재연's avatar
이재연 committed
5
6
7
    console.log(req.body)
    console.log('req.body.name=', req.body.name)
    const { name, number1, number2, id, password, password2, tel } = req.body
Kim, Subin's avatar
Kim, Subin committed
8
    try {
이재연's avatar
이재연 committed
9
        if(!isLength(password,{min:8, max:15})){
이재연's avatar
이재연 committed
10
            return res.status(422).json({message: '비밀번호는 8-15자리로 입력해주세요.'})
이재연's avatar
이재연 committed
11
        }
Kim, Subin's avatar
Kim, Subin committed
12
13
        const newUser = await new User ({
            name,
이재연's avatar
이재연 committed
14
15
            number1,
            number2,
이재연's avatar
이재연 committed
16
17
18
19
            id,
            password,
            password2,
            tel
Kim, Subin's avatar
Kim, Subin committed
20
21
22
23
24
25
        }).save()
        console.log(newUser)
        res.json(newUser)
        
    } catch (error) {
        console.log(error)
이재연's avatar
이재연 committed
26
        res.status(500).json({message:'죄송합니다. 다시 입력해 주십시오.'})
Kim, Subin's avatar
Kim, Subin committed
27
28
29
30
31
32
33
34
    }
}

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

export default  { signup, hello }