1
- var DatabaseAdapter = require ( '../DatabaseAdapter' ) ,
2
- triggers = require ( '../triggers' ) ,
3
- request = require ( 'request' ) ;
4
- const collection = "_Hooks" ;
1
+ /** @flow weak */
2
+
3
+ import * as DatabaseAdapter from "../DatabaseAdapter" ;
4
+ import * as triggers from "../triggers" ;
5
+ import * as Parse from "parse/node" ;
6
+ import * as request from "request" ;
7
+
8
+ const DefaultHooksCollectionName = "_Hooks" ;
5
9
6
10
export class HooksController {
7
-
8
- constructor ( applicationId ) {
9
- this . applicationId = applicationId ;
11
+ _applicationId : string ;
12
+ _collectionPrefix: string ;
13
+ _collection ;
14
+
15
+ constructor ( applicationId : string , collectionPrefix : string = '' ) {
16
+ this . _applicationId = applicationId ;
17
+ this . _collectionPrefix = collectionPrefix ;
10
18
}
11
19
12
20
database ( ) {
13
- return DatabaseAdapter . getDatabaseConnection ( this . applicationId ) ;
21
+ return DatabaseAdapter . getDatabaseConnection ( this . _applicationId , this . _collectionPrefix ) ;
14
22
}
15
23
16
24
collection ( ) {
17
25
if ( this . _collection ) {
18
26
return Promise . resolve ( this . _collection )
19
27
}
20
- return this . database ( ) . rawCollection ( collection ) . then ( ( collection ) => {
28
+ return this . database ( ) . rawCollection ( DefaultHooksCollectionName ) . then ( ( collection ) => {
21
29
this . _collection = collection ;
22
30
return collection ;
23
31
} ) ;
@@ -40,12 +48,12 @@ export class HooksController {
40
48
}
41
49
42
50
deleteFunction ( functionName ) {
43
- triggers . removeFunction ( functionName , this . applicationId ) ;
51
+ triggers . removeFunction ( functionName , this . _applicationId ) ;
44
52
return this . delete ( { functionName : functionName } ) ;
45
53
}
46
54
47
55
deleteTrigger ( className , triggerName ) {
48
- triggers . removeTrigger ( triggerName , className , this . applicationId ) ;
56
+ triggers . removeTrigger ( triggerName , className , this . _applicationId ) ;
49
57
return this . delete ( { className : className , triggerName : triggerName } ) ;
50
58
}
51
59
@@ -60,15 +68,15 @@ export class HooksController {
60
68
getOne ( query ) {
61
69
return this . collection ( )
62
70
. then ( coll => coll . findOne ( query , { _id : 0 } ) )
63
- . then ( hook => {
71
+ . then ( hook => {
64
72
return hook ;
65
73
} ) ;
66
74
}
67
75
68
76
get ( query ) {
69
77
return this . collection ( )
70
78
. then ( coll => coll . find ( query , { _id : 0 } ) . toArray ( ) )
71
- . then ( hooks => {
79
+ . then ( hooks => {
72
80
return hooks ;
73
81
} ) ;
74
82
}
@@ -102,9 +110,9 @@ export class HooksController {
102
110
var wrappedFunction = wrapToHTTPRequest ( hook ) ;
103
111
wrappedFunction . url = hook . url ;
104
112
if ( hook . className ) {
105
- triggers . addTrigger ( hook . triggerName , hook . className , wrappedFunction , this . applicationId )
113
+ triggers . addTrigger ( hook . triggerName , hook . className , wrappedFunction , this . _applicationId )
106
114
} else {
107
- triggers . addFunction ( hook . functionName , wrappedFunction , null , this . applicationId ) ;
115
+ triggers . addFunction ( hook . functionName , wrappedFunction , null , this . _applicationId ) ;
108
116
}
109
117
}
110
118
0 commit comments