Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,10 @@ describe('Cloud Code', () => {
url: 'https://some.url',
}),
array: ['a', 'b', 'c'],
arrayOfArray: [['a', 'b', 'c'], ['d', 'e', 'f']],
arrayOfArray: [
['a', 'b', 'c'],
['d', 'e', 'f'],
],
};
Parse.Cloud.run('params', params).then(() => {
done();
Expand Down Expand Up @@ -1763,8 +1766,15 @@ describe('beforeFind hooks', () => {
expect(jsonQuery.where.key).toEqual('value');
expect(jsonQuery.where.some).toEqual({ $gt: 10 });
expect(jsonQuery.include).toEqual('otherKey,otherValue');
expect(jsonQuery.excludeKeys).toBe('exclude');
expect(jsonQuery.limit).toEqual(100);
expect(jsonQuery.skip).toBe(undefined);
expect(jsonQuery.order).toBe('key');
expect(jsonQuery.keys).toBe('select');
expect(jsonQuery.readPreference).toBe('PRIMARY');
expect(jsonQuery.includeReadPreference).toBe('SECONDARY');
expect(jsonQuery.subqueryReadPreference).toBe('SECONDARY_PREFERRED');

expect(req.isGet).toEqual(false);
});

Expand All @@ -1773,6 +1783,10 @@ describe('beforeFind hooks', () => {
query.greaterThan('some', 10);
query.include('otherKey');
query.include('otherValue');
query.ascending('key');
query.select('select');
query.exclude('exclude');
query.readPreference('PRIMARY', 'SECONDARY', 'SECONDARY_PREFERRED');
query.find().then(() => {
done();
});
Expand Down Expand Up @@ -1824,6 +1838,25 @@ describe('beforeFind hooks', () => {
});
});

it('should use the modified exclude query', async () => {
Parse.Cloud.beforeFind('MyObject', req => {
const q = req.query;
q.exclude('number');
});

const obj = new Parse.Object('MyObject');
obj.set('number', 100);
obj.set('string', 'hello');
await obj.save();

const query = new Parse.Query('MyObject');
query.equalTo('objectId', obj.id);
const results = await query.find();
expect(results.length).toBe(1);
expect(results[0].get('number')).toBeUndefined();
expect(results[0].get('string')).toBe('hello');
});

it('should reject queries', done => {
Parse.Cloud.beforeFind('MyObject', () => {
return Promise.reject('Do not run that query');
Expand Down
20 changes: 8 additions & 12 deletions src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,22 +451,14 @@ export function maybeRunQueryTrigger(
restOptions,
});
}
const json = Object.assign({}, restOptions);
json.where = restWhere;

const parseQuery = new Parse.Query(className);
if (restWhere) {
parseQuery._where = restWhere;
}
parseQuery.withJSON(json);

let count = false;
if (restOptions) {
if (restOptions.include && restOptions.include.length > 0) {
parseQuery._include = restOptions.include.split(',');
}
if (restOptions.skip) {
parseQuery._skip = restOptions.skip;
}
if (restOptions.limit) {
parseQuery._limit = restOptions.limit;
}
count = !!restOptions.count;
}
const requestObject = getRequestQueryObject(
Expand Down Expand Up @@ -503,6 +495,10 @@ export function maybeRunQueryTrigger(
restOptions = restOptions || {};
restOptions.include = jsonQuery.include;
}
if (jsonQuery.excludeKeys) {
restOptions = restOptions || {};
restOptions.excludeKeys = jsonQuery.excludeKeys;
}
if (jsonQuery.keys) {
restOptions = restOptions || {};
restOptions.keys = jsonQuery.keys;
Expand Down