Access request headers from beforeSave Model Hook

后端 未结 5 879
执笔经年
执笔经年 2021-01-18 05:07

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          


        
5条回答
  •  遥遥无期
    2021-01-18 05:51

    If we assume that there is a relation comments of User -> Comment, you may also to try relation method POST /users/{user_id}/comments which will populate the foreignId (which can be added_by).

    Another thing is added_at. As far as I understand, validation hook is triggered before create hook. It means that validation will fail, since this field is marked as required in a model. The question is whether this field should be marked as required, since it is set by the server, and not required to be set by the client of the API.

提交回复
热议问题