Skip to content

Commit 28aeda3

Browse files
authored
feat: Allow Parse.Object pointers in Cloud Code arguments (#8490)
1 parent fd6a007 commit 28aeda3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Diff for: spec/CloudCode.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,27 @@ describe('Cloud Code', () => {
13521352
});
13531353
});
13541354

1355+
it('allow cloud to encode Parse Objects', async () => {
1356+
const user = new Parse.User();
1357+
user.setUsername('username');
1358+
user.setPassword('password');
1359+
user.set('deleted', false);
1360+
await user.signUp();
1361+
Parse.Cloud.define(
1362+
'deleteAccount',
1363+
async req => {
1364+
expect(req.params.object instanceof Parse.Object).toBeTrue();
1365+
req.params.object.set('deleted', true);
1366+
await req.params.object.save(null, { useMasterKey: true });
1367+
return 'Object deleted';
1368+
},
1369+
{
1370+
requireMaster: true,
1371+
}
1372+
);
1373+
await Parse.Cloud.run('deleteAccount', { object: user.toPointer() }, { useMasterKey: true });
1374+
});
1375+
13551376
it('beforeSave should not affect fetched pointers', done => {
13561377
Parse.Cloud.beforeSave('BeforeSaveUnchanged', () => {});
13571378

Diff for: src/Routers/FunctionsRouter.js

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ function parseObject(obj) {
1818
return Object.assign(new Date(obj.iso), obj);
1919
} else if (obj && obj.__type == 'File') {
2020
return Parse.File.fromJSON(obj);
21+
} else if (obj && obj.__type == 'Pointer') {
22+
return Parse.Object.fromJSON({
23+
__type: 'Pointer',
24+
className: obj.className,
25+
objectId: obj.objectId,
26+
});
2127
} else if (obj && typeof obj === 'object') {
2228
return parseParams(obj);
2329
} else {

0 commit comments

Comments
 (0)