Skip afterFind for Aggregate and Distinct Queries (#4596)
This commit is contained in:
@@ -1819,4 +1819,46 @@ describe('afterFind hooks', () => {
|
|||||||
Parse.Cloud.afterSave('_PushStatus', () => {});
|
Parse.Cloud.afterSave('_PushStatus', () => {});
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should skip afterFind hooks for aggregate', (done) => {
|
||||||
|
const hook = {
|
||||||
|
method: function() {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(hook, 'method').and.callThrough();
|
||||||
|
Parse.Cloud.afterFind('MyObject', hook.method);
|
||||||
|
const obj = new Parse.Object('MyObject')
|
||||||
|
const pipeline = [{
|
||||||
|
group: { objectId: {} }
|
||||||
|
}];
|
||||||
|
obj.save().then(() => {
|
||||||
|
const query = new Parse.Query('MyObject');
|
||||||
|
return query.aggregate(pipeline);
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results[0].objectId).toEqual(null);
|
||||||
|
expect(hook.method).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should skip afterFind hooks for distinct', (done) => {
|
||||||
|
const hook = {
|
||||||
|
method: function() {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(hook, 'method').and.callThrough();
|
||||||
|
Parse.Cloud.afterFind('MyObject', hook.method);
|
||||||
|
const obj = new Parse.Object('MyObject')
|
||||||
|
obj.set('score', 10);
|
||||||
|
obj.save().then(() => {
|
||||||
|
const query = new Parse.Query('MyObject');
|
||||||
|
return query.distinct('score');
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results[0]).toEqual(10);
|
||||||
|
expect(hook.method).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -584,6 +584,10 @@ RestQuery.prototype.runAfterFindTrigger = function() {
|
|||||||
if (!hasAfterFindHook) {
|
if (!hasAfterFindHook) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
// Skip Aggregate and Distinct Queries
|
||||||
|
if (this.findOptions.pipeline || this.findOptions.distinct) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
// Run afterFind trigger and set the new results
|
// Run afterFind trigger and set the new results
|
||||||
return triggers.maybeRunAfterFindTrigger(triggers.Types.afterFind, this.auth, this.className,this.response.results, this.config).then((results) => {
|
return triggers.maybeRunAfterFindTrigger(triggers.Types.afterFind, this.auth, this.className,this.response.results, this.config).then((results) => {
|
||||||
this.response.results = results;
|
this.response.results = results;
|
||||||
|
|||||||
Reference in New Issue
Block a user