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

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

export default  { signup, hello }