Pass request.query to afterFind (#6960)
* Initial Commit * Update triggers.js
This commit is contained in:
@@ -2018,6 +2018,37 @@ describe('beforeFind hooks', () => {
|
||||
});
|
||||
|
||||
describe('afterFind hooks', () => {
|
||||
it('should add afterFind trigger', done => {
|
||||
Parse.Cloud.afterFind('MyObject', req => {
|
||||
const q = req.query;
|
||||
expect(q instanceof Parse.Query).toBe(true);
|
||||
const jsonQuery = q.toJSON();
|
||||
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');
|
||||
});
|
||||
|
||||
const query = new Parse.Query('MyObject');
|
||||
query.equalTo('key', 'value');
|
||||
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();
|
||||
});
|
||||
});
|
||||
it('should add afterFind trigger using get', done => {
|
||||
Parse.Cloud.afterFind('MyObject', req => {
|
||||
for (let i = 0; i < req.objects.length; i++) {
|
||||
|
||||
@@ -794,6 +794,11 @@ RestQuery.prototype.runAfterFindTrigger = function() {
|
||||
if (this.findOptions.pipeline || this.findOptions.distinct) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const json = Object.assign({}, this.restOptions);
|
||||
json.where = this.restWhere;
|
||||
const parseQuery = new Parse.Query(this.className);
|
||||
parseQuery.withJSON(json);
|
||||
// Run afterFind trigger and set the new results
|
||||
return triggers
|
||||
.maybeRunAfterFindTrigger(
|
||||
@@ -801,7 +806,8 @@ RestQuery.prototype.runAfterFindTrigger = function() {
|
||||
this.auth,
|
||||
this.className,
|
||||
this.response.results,
|
||||
this.config
|
||||
this.config,
|
||||
parseQuery
|
||||
)
|
||||
.then(results => {
|
||||
// Ensure we properly set the className back
|
||||
|
||||
@@ -416,7 +416,8 @@ export function maybeRunAfterFindTrigger(
|
||||
auth,
|
||||
className,
|
||||
objects,
|
||||
config
|
||||
config,
|
||||
query
|
||||
) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const trigger = getTrigger(className, triggerType, config.applicationId);
|
||||
@@ -424,6 +425,9 @@ export function maybeRunAfterFindTrigger(
|
||||
return resolve();
|
||||
}
|
||||
const request = getRequestObject(triggerType, auth, null, null, config);
|
||||
if (query) {
|
||||
request.query = query;
|
||||
}
|
||||
const { success, error } = getResponseObject(
|
||||
request,
|
||||
object => {
|
||||
|
||||
Reference in New Issue
Block a user