@@ -4,6 +4,16 @@ import { HooksController } from '../Controllers/HooksController';
4
4
import * as middleware from "../middlewares" ;
5
5
6
6
export class HooksRouter extends PromiseRouter {
7
+
8
+ static stripObjectId ( result ) {
9
+ delete result . objectId ;
10
+ return result ;
11
+ }
12
+
13
+ static stripObjectIds ( results ) {
14
+ return results . map ( result => HooksRouter . stripObjectId ) ;
15
+ }
16
+
7
17
createHook ( aHook , config ) {
8
18
return config . hooksController . createHook ( aHook ) . then ( ( hook ) => ( { response : hook } ) ) ;
9
19
} ;
@@ -23,12 +33,12 @@ export class HooksRouter extends PromiseRouter {
23
33
if ( ! foundFunction ) {
24
34
throw new Parse . Error ( 143 , `no function named: ${ req . params . functionName } is defined` ) ;
25
35
}
26
- return Promise . resolve ( { response : foundFunction } ) ;
36
+ return Promise . resolve ( { response : HooksRouter . stripObjectId ( foundFunction ) } ) ;
27
37
} ) ;
28
38
}
29
-
39
+
30
40
return hooksController . getFunctions ( ) . then ( ( functions ) => {
31
- return { response : functions || [ ] } ;
41
+ return { response : HooksRouter . stripObjectIds ( functions || [ ] ) } ;
32
42
} , ( err ) => {
33
43
throw err ;
34
44
} ) ;
@@ -37,16 +47,17 @@ export class HooksRouter extends PromiseRouter {
37
47
handleGetTriggers ( req ) {
38
48
var hooksController = req . config . hooksController ;
39
49
if ( req . params . className && req . params . triggerName ) {
40
-
41
50
return hooksController . getTrigger ( req . params . className , req . params . triggerName ) . then ( ( foundTrigger ) => {
42
51
if ( ! foundTrigger ) {
43
52
throw new Parse . Error ( 143 , `class ${ req . params . className } does not exist` ) ;
44
53
}
45
- return Promise . resolve ( { response : foundTrigger } ) ;
54
+ return Promise . resolve ( { response : HooksRouter . stripObjectId ( foundTrigger ) } ) ;
46
55
} ) ;
47
56
}
48
-
49
- return hooksController . getTriggers ( ) . then ( ( triggers ) => ( { response : triggers || [ ] } ) ) ;
57
+
58
+ return hooksController . getTriggers ( ) . then ( ( triggers ) => {
59
+ return { response : HooksRouter . stripObjectIds ( triggers || [ ] ) } ;
60
+ } ) ;
50
61
}
51
62
52
63
handleDelete ( req ) {
@@ -73,10 +84,10 @@ export class HooksRouter extends PromiseRouter {
73
84
hook . url = req . body . url
74
85
} else {
75
86
throw new Parse . Error ( 143 , "invalid hook declaration" ) ;
76
- }
87
+ }
77
88
return this . updateHook ( hook , req . config ) ;
78
89
}
79
-
90
+
80
91
handlePut ( req ) {
81
92
var body = req . body ;
82
93
if ( body . __op == "Delete" ) {
@@ -85,7 +96,7 @@ export class HooksRouter extends PromiseRouter {
85
96
return this . handleUpdate ( req ) ;
86
97
}
87
98
}
88
-
99
+
89
100
mountRoutes ( ) {
90
101
this . route ( 'GET' , '/hooks/functions' , middleware . promiseEnforceMasterKeyAccess , this . handleGetFunctions . bind ( this ) ) ;
91
102
this . route ( 'GET' , '/hooks/triggers' , middleware . promiseEnforceMasterKeyAccess , this . handleGetTriggers . bind ( this ) ) ;
0 commit comments