Skip to content

Commit

Permalink
add context to Parse.Object.save (#6626)
Browse files Browse the repository at this point in the history
* added failing test

* added parsing of context in REST save request

* undo lint changes
  • Loading branch information
mtrezza authored Apr 28, 2020
1 parent 61546aa commit 288e746
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2911,4 +2911,17 @@ describe('afterLogin hook', () => {
await Parse.User.logIn('testuser', 'p@ssword');
done();
});

it('should have access to context as save argument', async () => {
// Declare triggers
Parse.Cloud.beforeSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
// Save object
const obj = new TestObject();
await obj.save(null, { context: { a: 'a' } });
});
});
5 changes: 5 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function RestWrite(
}

if (!query) {
// Parse context
if (data._context && data._context instanceof Object) {
this.context = data._context;
delete data._context;
}
if (this.config.allowCustomObjectId) {
if (
Object.prototype.hasOwnProperty.call(data, 'objectId') &&
Expand Down

0 comments on commit 288e746

Please sign in to comment.