Skip to content

Commit ec37789

Browse files
dblythyEmpiDev
authored andcommitted
wip
1 parent 6daa039 commit ec37789

File tree

2 files changed

+77
-64
lines changed

2 files changed

+77
-64
lines changed

src/rest.js

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -23,80 +23,90 @@ function checkTriggers(className, config, types) {
2323
function checkLiveQuery(className, config) {
2424
return config.liveQueryController && config.liveQueryController.hasLiveQuery(className);
2525
}
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+
);
2646

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,
3356
className,
34-
restWhere,
35-
restOptions,
57+
objects,
3658
config,
37-
auth,
59+
restWhere,
3860
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+
);
6094
};
6195

62-
// get is just like find but only queries an objectId.
6396
const get = async (config, auth, className, objectId, restOptions, clientSDK, context) => {
64-
var restWhere = { objectId };
6597
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+
);
97108
};
98109

99-
// Returns a promise that doesn't resolve to any useful value.
100110
function del(config, auth, className, objectId, context) {
101111
if (typeof objectId !== 'string') {
102112
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad objectId');

src/triggers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ export function maybeRunAfterFindTrigger(
471471
);
472472
request.objects = objects.map(object => {
473473
//setting the class name to transform into parse object
474+
if (object instanceof Parse.Object) {
475+
return object;
476+
}
474477
object.className = className;
475478
return Parse.Object.fromJSON(object);
476479
});

0 commit comments

Comments
 (0)