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" ;
59
610export 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 ;
1018 }
1119
1220 database ( ) {
13- return DatabaseAdapter . getDatabaseConnection ( this . applicationId ) ;
21+ return DatabaseAdapter . getDatabaseConnection ( this . _applicationId , this . _collectionPrefix ) ;
1422 }
1523
1624 collection ( ) {
1725 if ( this . _collection ) {
1826 return Promise . resolve ( this . _collection )
1927 }
20- return this . database ( ) . rawCollection ( collection ) . then ( ( collection ) => {
28+ return this . database ( ) . rawCollection ( DefaultHooksCollectionName ) . then ( ( collection ) => {
2129 this . _collection = collection ;
2230 return collection ;
2331 } ) ;
@@ -40,12 +48,12 @@ export class HooksController {
4048 }
4149
4250 deleteFunction ( functionName ) {
43- triggers . removeFunction ( functionName , this . applicationId ) ;
51+ triggers . removeFunction ( functionName , this . _applicationId ) ;
4452 return this . delete ( { functionName : functionName } ) ;
4553 }
4654
4755 deleteTrigger ( className , triggerName ) {
48- triggers . removeTrigger ( triggerName , className , this . applicationId ) ;
56+ triggers . removeTrigger ( triggerName , className , this . _applicationId ) ;
4957 return this . delete ( { className : className , triggerName : triggerName } ) ;
5058 }
5159
@@ -60,15 +68,15 @@ export class HooksController {
6068 getOne ( query ) {
6169 return this . collection ( )
6270 . then ( coll => coll . findOne ( query , { _id : 0 } ) )
63- . then ( hook => {
71+ . then ( hook => {
6472 return hook ;
6573 } ) ;
6674 }
6775
6876 get ( query ) {
6977 return this . collection ( )
7078 . then ( coll => coll . find ( query , { _id : 0 } ) . toArray ( ) )
71- . then ( hooks => {
79+ . then ( hooks => {
7280 return hooks ;
7381 } ) ;
7482 }
@@ -102,9 +110,9 @@ export class HooksController {
102110 var wrappedFunction = wrapToHTTPRequest ( hook ) ;
103111 wrappedFunction . url = hook . url ;
104112 if ( hook . className ) {
105- triggers . addTrigger ( hook . triggerName , hook . className , wrappedFunction , this . applicationId )
113+ triggers . addTrigger ( hook . triggerName , hook . className , wrappedFunction , this . _applicationId )
106114 } else {
107- triggers . addFunction ( hook . functionName , wrappedFunction , null , this . applicationId ) ;
115+ triggers . addFunction ( hook . functionName , wrappedFunction , null , this . _applicationId ) ;
108116 }
109117 }
110118
0 commit comments