Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //...
- // follow the given user
- router.post('/:username/follow', auth.required, function(req, res, next){
- var profileId = req.profile._id;
- // grab the user from the request and call the follow method.
- User.findById(req.payload.id).then(function(user){
- if (!user) { return res.sendStatus(401); }
- return user.follow(profileId).then(function(){
- return res.json({profile: req.profile.toProfileJSONFor(user)});
- });
- }).catch(next);
- });
- // unfollow the given user
- router.delete('/:username/follow', auth.required, function(req, res, next){
- var profileId = req.profile._id;
- // find user, call unfollow request
- User.findById(req.payload.id).then(function(user){
- if (!user) { return res.sendStatus(401); }
- return user.unfollow(profileId).then(function(){
- return res.json({profile: req.profile.toProfileJSONFor(user)});
- });
- }).catch(next);
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement