-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add a toJSON bundled hook like mongoose #18
Comments
I'm wondering if we should start the common hook collection module right away and provide a var transform = require('feathers-common-hooks/transform');
app.service('todos').after(transform('toJSON'));
app.service('todos').after(transform(function(data) {
// Do something here
})); Which in the first case will call |
Ya I'm liking that idea. Especially because we have to handle arrays and pagination sometimes I can see that as a potential pitfall if people have to implement the hooks themselves. |
No longer required as of v2.0.0 since it returns regular JS objects by default. |
I think this is still required. I have use case of few related models. Upon using {
"role.roleId": "",
"role.name": ""
} instead of {
"role": {
"roleId": "",
"name": ""
}
} Just this would've been fine as it'd be easy to convert the first result to second. But the real issue comes when the included results are an array, in which case the above result doesn't contain all values, just one. (Let's say if roles had a bunch of permissions related to it, it'd just return one permission and not all) So there is no option but to use |
Though of course a very simple solution exists: all: [
hook => ({
...hook,
result: hook.result.toJSON()
}),
discard('password')
] But I'd say a transform hook is still a good idea, because the explicit presence of it in the docs will really help people. |
I just updated my dependencies and now my results are also flattened like above. Why is that the case? That does not make sense for me. |
No description provided.
The text was updated successfully, but these errors were encountered: