Created
September 23, 2014 19:55
-
-
Save joshuakfarrar/ca9e2a8ed55d1ab039d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.show = function (req, res, next) { | |
var username = req.params.username; | |
var query = User.where({ username: username }); | |
query.findOne(function (err, user) { | |
if (err) return next(err); | |
if (!user) return res.send(401); | |
res.json(user.profile); // this is where the magic happens | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var UserSchema = new Schema({ | |
username: String, | |
role: { | |
type: String, | |
default: 'user' | |
}, | |
}); | |
UserSchema | |
.virtual('profile') | |
.get(function() { | |
return { | |
'username': this.username, | |
'role': this.role | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment