Skip to content

Commit 0d42676

Browse files
committed
Provide isGet context to afterFind trigger
1 parent 98be232 commit 0d42676

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/RestQuery.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ async function RestQuery({
5050
if (![RestQuery.Method.find, RestQuery.Method.get].includes(method)) {
5151
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad query type');
5252
}
53+
const isGet = method === RestQuery.Method.get;
5354
enforceRoleSecurity(method, className, auth);
5455
const result = runBeforeFind
5556
? await triggers.maybeRunQueryTrigger(
@@ -60,7 +61,7 @@ async function RestQuery({
6061
config,
6162
auth,
6263
context,
63-
method === RestQuery.Method.get
64+
isGet
6465
)
6566
: Promise.resolve({ restWhere, restOptions });
6667

@@ -72,7 +73,8 @@ async function RestQuery({
7273
result.restOptions || restOptions,
7374
clientSDK,
7475
runAfterFind,
75-
context
76+
context,
77+
isGet
7678
);
7779
}
7880

@@ -101,7 +103,8 @@ function _UnsafeRestQuery(
101103
restOptions = {},
102104
clientSDK,
103105
runAfterFind = true,
104-
context
106+
context,
107+
isGet
105108
) {
106109
this.config = config;
107110
this.auth = auth;
@@ -113,6 +116,7 @@ function _UnsafeRestQuery(
113116
this.response = null;
114117
this.findOptions = {};
115118
this.context = context || {};
119+
this.isGet = isGet;
116120
if (!this.auth.isMaster) {
117121
if (this.className == '_Session') {
118122
if (!this.auth.user) {
@@ -914,7 +918,8 @@ _UnsafeRestQuery.prototype.runAfterFindTrigger = function () {
914918
this.response.results,
915919
this.config,
916920
parseQuery,
917-
this.context
921+
this.context,
922+
this.isGet
918923
)
919924
.then(results => {
920925
// Ensure we properly set the className back

src/rest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ async function runFindTriggers(
5858
objectsFromBeforeFind,
5959
config,
6060
new Parse.Query(className).withJSON({ where: restWhere, ...restOptions }),
61-
context
61+
context,
62+
isGet
6263
);
6364

6465
return {

src/triggers.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ export function getRequestObject(
260260
parseObject,
261261
originalParseObject,
262262
config,
263-
context
263+
context,
264+
isGet
264265
) {
265266
const request = {
266267
triggerName: triggerType,
@@ -271,6 +272,10 @@ export function getRequestObject(
271272
ip: config.ip,
272273
};
273274

275+
if (isGet !== undefined) {
276+
request.isGet = !!isGet;
277+
}
278+
274279
if (originalParseObject) {
275280
request.original = originalParseObject;
276281
}
@@ -444,7 +449,8 @@ export function maybeRunAfterFindTrigger(
444449
objectsInput,
445450
config,
446451
query,
447-
context
452+
context,
453+
isGet
448454
) {
449455
return new Promise((resolve, reject) => {
450456
const trigger = getTrigger(classNameQuery, triggerType, config.applicationId);
@@ -456,7 +462,7 @@ export function maybeRunAfterFindTrigger(
456462
return resolve(objectsInput || []);
457463
}
458464

459-
const request = getRequestObject(triggerType, auth, null, null, config, context);
465+
const request = getRequestObject(triggerType, auth, null, null, config, context, isGet);
460466
if (query instanceof Parse.Query) {
461467
request.query = query;
462468
} else if (typeof query === 'object' && query !== null) {

0 commit comments

Comments
 (0)