Skip to content

Commit 7e153d4

Browse files
committed
Merge pull request #865 from ParsePlatform/fosco.457
beforeSave changes should propagate to the response
2 parents b3a52fb + 3266d59 commit 7e153d4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

spec/ParseAPI.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,23 @@ describe('miscellaneous', function() {
967967
});
968968
});
969969

970+
it('beforeSave change propagates through the save response', (done) => {
971+
Parse.Cloud.beforeSave('ChangingObject', function(request, response) {
972+
request.object.set('foo', 'baz');
973+
response.success();
974+
});
975+
let obj = new Parse.Object('ChangingObject');
976+
obj.save({ foo: 'bar' }).then((objAgain) => {
977+
expect(objAgain.get('foo')).toEqual('baz');
978+
Parse.Cloud._removeHook("Triggers", "beforeSave", "ChangingObject");
979+
done();
980+
}, (e) => {
981+
Parse.Cloud._removeHook("Triggers", "beforeSave", "ChangingObject");
982+
fail('Should not have failed to save.');
983+
done();
984+
});
985+
});
986+
970987
it('dedupes an installation properly and returns updatedAt', (done) => {
971988
let headers = {
972989
'Content-Type': 'application/json',

src/RestWrite.js

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ RestWrite.prototype.runBeforeTrigger = function() {
164164
}).then((response) => {
165165
if (response && response.object) {
166166
this.data = response.object;
167+
this.storage['changedByTrigger'] = true;
167168
// We should delete the objectId for an update write
168169
if (this.query && this.query.objectId) {
169170
delete this.data.objectId
@@ -806,6 +807,9 @@ RestWrite.prototype.runDatabaseOperation = function() {
806807
objectId: this.data.objectId,
807808
createdAt: this.data.createdAt
808809
};
810+
if (this.storage['changedByTrigger']) {
811+
Object.assign(resp, this.data);
812+
}
809813
if (this.storage['token']) {
810814
resp.sessionToken = this.storage['token'];
811815
}

0 commit comments

Comments
 (0)