Skip to content

Commit

Permalink
wip #76 revert and fix studyGroup.controller createStudyGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe229 committed Mar 24, 2017
1 parent 4ded3e9 commit a8a1caa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion server/controllers/studyGroup.controller.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import User from '../models/user'
import StudyGroup from '../models/studyGroup';
import Message from '../models/message';
import cuid from 'cuid';
Expand Down Expand Up @@ -29,7 +30,18 @@ export function createStudyGroup(req, res) {
if (err) {
return res.status(500).send(err);
}
return res.json(saved);
User.findOne({ cuid: req.body.cuid }).exec((err, user) => {
if (err) {
return res.status(500).send(err);
}
user.studyGroups.push(newStudyGroup);
user.save((err, saved) => {
if (err) {
return res.status(500).send(err);
}
return res.json({ studyGroup: saved });
});
});
});
}

Expand Down
4 changes: 3 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ passport.serializeUser(function (user, done) {

passport.deserializeUser(function (id, done) {
User.findOne({ 'cuid': id }, function (err, user) {
user.password = undefined;
if (user != null) {
user.password = undefined;
}
done(err, user);
});
});
Expand Down

0 comments on commit a8a1caa

Please sign in to comment.