-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Make possible to alter response using the after save trigger #5814
Make possible to alter response using the after save trigger #5814
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5814 +/- ##
==========================================
- Coverage 93.67% 93.66% -0.02%
==========================================
Files 146 146
Lines 10236 10242 +6
==========================================
+ Hits 9589 9593 +4
- Misses 647 649 +2
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
by using protected fields, you can mark a field as master only, or give it permission for any other role or pointer. |
Hi @acinader, thanks for the quick answer. I will check the |
@brunoMaurice Thanks for the PR! But I actually didn't understand very well the use case. The REST API only returns |
If we follow the documentation it should be like that but if you have a
The response of the request will have |
In my opinion, that's a weird behavior of Parse Server but you are right. Just checked here and it seems that it was designed to send back the changed fields in the before save trigger so the client can be aware of what happened there. Considering this, I think your PR makes totally sense and I will review it right now. |
|
||
it('test afterSave response object is return', done => { | ||
Parse.Cloud.afterSave('TestObject2', function(req) { | ||
const jsonObject = req.object.toJSON(); |
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.
I think it is not so straightforward for others users to use this capability. Can you test just using the code below?
req.object.unset('todelete');
req.object.set('toadd', true);
return req.object;
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.
It's actually an other issue I had. If you do that you will have :
{
"tokeep": true,
"createdAt": "2019-07-18T09:12:58.496Z",
"todelete": {
"__op": "Delete"
},
"updatedAt": "2019-07-18T09:12:58.496Z",
"toadd": true,
"objectId": "zC2AmMvGxM"
}
the __op
is not really great response :/
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.
Can you try like this?
req.object.unset('todelete');
req.object.set('toadd', true);
return req.object._toFullJSON();
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.
With that I have :
{ todelete: { __op: 'Delete' },
tokeep: true,
createdAt: '2019-07-25T13:49:32.552Z',
updatedAt: '2019-07-25T13:49:32.552Z',
toadd: true,
objectId: '4lgUT2xWo5',
__type: 'Object',
className: 'TestObject2' }
with toJson
:
{ todelete: { __op: 'Delete' },
tokeep: true,
createdAt: '2019-07-25T13:49:32.552Z',
updatedAt: '2019-07-25T13:49:32.552Z',
toadd: true,
objectId: '4lgUT2xWo5' }
The test is running fine in local don't get what's wrong with the CI :s |
…ommunity#5814) * make possible to alter response using the after save trigger like for after find * code clearing to follow same object checking * remove console log debug * fix test unit
The trigger response is only handle for beforeSave and afterFind event let handle it also for afterSave.
In my use case, I do some data manipulation/injection using the
beforeSave
trigger and I don't want to show them. Since it's not possible to define an hidden field (like the hard coded field password), It would be great to be able to alter the object usingafter-save
like we can do it withafter-find
.Let me know if you have some suggestion or question about the change :)