-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Adding support for AfterFind #2962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ide certain fields or rows from result set in a more dynamic way than the current capabilities
5a58724#diff-dc168077f7f927cefd5df84cb82228a6R481 variable name should be hasAfterFindHook - not hasAfterSaveHook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, can you address the nits and we'll be able to merge that.
@@ -640,4 +660,7 @@ function findObjectWithKey(root, key) { | |||
} | |||
} | |||
|
|||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the lines
}; | ||
logTriggerSuccessBeforeHook(triggerType, className, 'AfterFind', JSON.stringify(results), auth); | ||
var resultsAsParseObjects = []; | ||
for (var i=0;i<results.length;i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use a map here. We avoid for loops with indexes
response.results = resultsAsParseObjects; | ||
var triggerPromise = trigger(request, response); | ||
var modifiedJSONResults = []; | ||
for(var i = 0;i<response.results.length;i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
for(var i = 0;i<response.results.length;i++){ | ||
modifiedJSONResults.push(response.results[i].toJSON()); | ||
} | ||
logTriggerAfterHook(triggerType,className, JSON.stringify(modifiedJSONResults), auth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spaces
}); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add trailing \n
} | ||
logTriggerAfterHook(triggerType,className, JSON.stringify(modifiedJSONResults), auth); | ||
if (triggerPromise && typeof triggerPromise.then === "function") { | ||
return reject(new Parse.Error(Parse.Error.SCRIPT_FAILED, "Promise not supported by AfterFind")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the beforeFind trigger uses promises, and promises are more convenient that the callback, we should put it there too
* Close all alive connections on SIGINT/SIGTERM * Add a comment referencing the node issue.
Currently in the logs if an invalid function is called the error message just says "invalid function" which is decidedly unhelpful when looking through server logs. Now it will say "Invalid function: "functionName""
…ide certain fields or rows from result set in a more dynamic way than the current capabilities
@jbpringuey updated the pull request - view changes |
messed up the rebase, it is showing other's commit too let me try to fix it |
…ide certain fields or rows from result set in a more dynamic way than the current capabilities
* Close all alive connections on SIGINT/SIGTERM * Add a comment referencing the node issue.
Currently in the logs if an invalid function is called the error message just says "invalid function" which is decidedly unhelpful when looking through server logs. Now it will say "Invalid function: "functionName""
@jbpringuey updated the pull request - view changes |
going to resubmit ... |
For security reasons, I need to hide certain fields (like email) and rows from the API for use cases which are not supported by the current ACL framework. This plugin will enable all sorts of manipulation. Next step would be to support promise to maybe augment the response from other data source.