The sailsjs model attribute method toJSON is very handy for processing model attributes before sending back to client. However, this method does not take any parameters and I cannot pass additional information to the method that can be used for processing attributes.
In my particular case, I need to check if I should send an attribute by comparing logged in user id (req.user.id). E.g.
toJSON: function () {
var obj = this.toObject();
var result = {};
if (req.user.id === 123) { // How can I access req from inside toJSON?
// do something here ...
}
}
I could not find a way to access the req parameter from inside toJSON. Any suggestions?