How can i access the details of the user who raise the request from a Model Hook
Comment.beforeSave = function(next,com) {
//Want to add 2 more properties
It seems that you can't update related model with simply overriding ctx.req.body
. Instead of you should override ctx.args.data
- it looks like this ctx parameter is used to initalize the related model.
So it will look like that:
MainItem.beforeRemote('**', function(ctx, user, next) {
if(ctx.methodString == 'leave_request.prototype.__create__comments'){
ctx.args.data.added_by = ctx.req.accessToken.userId;
ctx.args.data.added_at = new Date();
console.log("Added headers as .."+ctx.args.data.added_by);
}
else{ ... }
next();