Skip to content

Commit

Permalink
Prefs (#37)
Browse files Browse the repository at this point in the history
* user prefs routes: create new, get one, update one

* added general user routes
  • Loading branch information
dyoungsmith authored and johannaperez committed Oct 5, 2016
1 parent 84a2768 commit 9847415
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions server/app/routes/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ router.get('/', (req, res, next) => {
.catch(next);
});

// Create new preferences
// GET one user
router.get('/:userId', (req, res, next) => {
User.findById(req.params.userId)
.then(foundUser => {
if (!foundUser) res.sendStatus(404);
else {
res.status(200).json(foundUser);
}
})
.catch(next);
});

// Create new preference
router.post('/:userId/preferences', (req, res, next) => {
req.body.userId = req.params.userId;
UserPref.create(req.body)
Expand All @@ -26,7 +38,7 @@ router.post('/:userId/preferences', (req, res, next) => {
.catch(next);
});

// Get a particular user loaded with their preferences
// Get a user's preference
router.get('/:userId/preferences', (req, res, next) => {
UserPref.findOne({
where: {
Expand All @@ -39,7 +51,7 @@ router.get('/:userId/preferences', (req, res, next) => {
.catch(next);
});

// Edit user preferences
// Edit a user's preference
router.put('/:userId/preferences', (req, res, next) => {
UserPref.findOne({
where: {
Expand Down

0 comments on commit 9847415

Please sign in to comment.