Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Created September 23, 2014 19:55
Show Gist options
  • Save joshuakfarrar/ca9e2a8ed55d1ab039d3 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/ca9e2a8ed55d1ab039d3 to your computer and use it in GitHub Desktop.
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
});
};
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