-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
64 lines (59 loc) · 1.45 KB
/
router.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { Router } = require('express')
const User = require('./model')
const bcrypt = require('bcrypt')
const router = new Router()
router
.post(
'/user',
(req, res, next) => {
bcrypt.hash(req.body.password, 10, (err, hash) => {
if (err) {
return res.status(500).json({
error: err
})
} else {
const user = new User({
name: req.body.name,
score: req.body.score,
password: hash
})
user.save()
.then(result => {
console.log(result);
res.status(201).json({
message: 'User created'
})
})
.catch(err => {
console.log(err)
res.status(500).json({
error: err
})
})
}
})
})
// if(!name || !password) {
// res.status(400).send({
// message: 'Please supply a valid name and password'
// })
// }
// //should add password_confirmation: req.body.password_confirmation
// },
// //if (user.email && user.pass && user.pass_confirm) {
// // if user.pass
// // }
// User
// .create(user)
// .then(user => {
// res
// .status(200)
// .send(user)
// })
// .catch(err =>
// res
// .status(422)
// .send(next(err))
// )
// )
module.exports = router