Skip to content

Commit

Permalink
feat: Create user controller
Browse files Browse the repository at this point in the history
see: #10
  • Loading branch information
sujinleeme committed Jul 1, 2018
1 parent 84d1784 commit c4b8fd8
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions server/controller/user.ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const User = require("./../models/User")
const InputAudio = require("./../models/InputAudio")

module.exports = {
addUser: (req, res, next) => {
new User(req.body).save((err, newUser) => {
if (err)
res.send(err)
else if (!newUser)
res.send(400)
else
res.send(newUser)
next()
})
},

getUser: (req, res, next) => {
User.findById(req.params.id).then((err, user) => {
if (err)
res.send(err)
else if (!user)
res.send(404)
else
res.send(user)
next()
})
},

getUserProfile: (req, res, next) => {
User.findById(req.params.id).then(_user => {
return InputAudio.find({"author": req.params.id}).then((_audios) =>
res.json({user: _user, inputAudios: _audios})
)
}).catch((err) => console.log(err))
}
}


0 comments on commit c4b8fd8

Please sign in to comment.