@@ -23,80 +23,90 @@ function checkTriggers(className, config, types) {
23
23
function checkLiveQuery ( className , config ) {
24
24
return config . liveQueryController && config . liveQueryController . hasLiveQuery ( className ) ;
25
25
}
26
+ async function runFindTriggers (
27
+ config ,
28
+ auth ,
29
+ className ,
30
+ restWhere ,
31
+ restOptions ,
32
+ clientSDK ,
33
+ context ,
34
+ isGet
35
+ ) {
36
+ const result = await triggers . maybeRunQueryTrigger (
37
+ triggers . Types . beforeFind ,
38
+ className ,
39
+ restWhere ,
40
+ restOptions ,
41
+ config ,
42
+ auth ,
43
+ context ,
44
+ isGet
45
+ ) ;
26
46
27
- // Returns a promise for an object with optional keys 'results' and 'count'.
28
- const find = async ( config , auth , className , restWhere , restOptions , clientSDK , context ) => {
29
- enforceRoleSecurity ( 'find' , className , auth ) ;
30
- return triggers
31
- . maybeRunQueryTrigger (
32
- triggers . Types . beforeFind ,
47
+ restWhere = result . restWhere || restWhere ;
48
+ restOptions = result . restOptions || restOptions ;
49
+
50
+ if ( result ?. objects ) {
51
+ const objects = result . objects ;
52
+
53
+ await triggers . maybeRunAfterFindTrigger (
54
+ triggers . Types . afterFind ,
55
+ auth ,
33
56
className ,
34
- restWhere ,
35
- restOptions ,
57
+ objects ,
36
58
config ,
37
- auth ,
59
+ restWhere ,
38
60
context
39
- )
40
- . then ( async result => {
41
- restWhere = result . restWhere || restWhere ;
42
- restOptions = result . restOptions || restOptions ;
43
- if ( result ?. objects ) {
44
- return {
45
- results : result . objects . map ( row => row . _toFullJSON ( ) ) ,
46
- } ;
47
- }
48
- const query = await RestQuery ( {
49
- method : RestQuery . Method . find ,
50
- config,
51
- auth,
52
- className,
53
- restWhere,
54
- restOptions,
55
- clientSDK,
56
- context,
57
- } ) ;
58
- return query . execute ( ) ;
59
- } ) ;
61
+ ) ;
62
+
63
+ return {
64
+ results : objects . map ( row => row . _toFullJSON ( ) ) ,
65
+ } ;
66
+ }
67
+
68
+ const query = await RestQuery ( {
69
+ method : isGet ? RestQuery . Method . get : RestQuery . Method . find ,
70
+ config,
71
+ auth,
72
+ className,
73
+ restWhere,
74
+ restOptions,
75
+ clientSDK,
76
+ context,
77
+ } ) ;
78
+
79
+ return query . execute ( ) ;
80
+ }
81
+
82
+ const find = async ( config , auth , className , restWhere , restOptions , clientSDK , context ) => {
83
+ enforceRoleSecurity ( 'find' , className , auth ) ;
84
+ return runFindTriggers (
85
+ config ,
86
+ auth ,
87
+ className ,
88
+ restWhere ,
89
+ restOptions ,
90
+ clientSDK ,
91
+ context ,
92
+ false
93
+ ) ;
60
94
} ;
61
95
62
- // get is just like find but only queries an objectId.
63
96
const get = async ( config , auth , className , objectId , restOptions , clientSDK , context ) => {
64
- var restWhere = { objectId } ;
65
97
enforceRoleSecurity ( 'get' , className , auth ) ;
66
- return triggers
67
- . maybeRunQueryTrigger (
68
- triggers . Types . beforeFind ,
69
- className ,
70
- restWhere ,
71
- restOptions ,
72
- config ,
73
- auth ,
74
- context ,
75
- true
76
- )
77
- . then ( async result => {
78
- restWhere = result . restWhere || restWhere ;
79
- restOptions = result . restOptions || restOptions ;
80
- if ( result ?. objects ) {
81
- return {
82
- results : result . objects . map ( row => row . _toFullJSON ( ) ) ,
83
- } ;
84
- }
85
- const query = await RestQuery ( {
86
- method : RestQuery . Method . get ,
87
- config,
88
- auth,
89
- className,
90
- restWhere,
91
- restOptions,
92
- clientSDK,
93
- context,
94
- } ) ;
95
- return query . execute ( ) ;
96
- } ) ;
98
+ return runFindTriggers (
99
+ config ,
100
+ auth ,
101
+ className ,
102
+ { objectId } ,
103
+ restOptions ,
104
+ clientSDK ,
105
+ context ,
106
+ true
107
+ ) ;
97
108
} ;
98
109
99
- // Returns a promise that doesn't resolve to any useful value.
100
110
function del ( config , auth , className , objectId , context ) {
101
111
if ( typeof objectId !== 'string' ) {
102
112
throw new Parse . Error ( Parse . Error . INVALID_JSON , 'bad objectId' ) ;
0 commit comments