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