@@ -5,10 +5,8 @@ const async = require('async'),
55 common = require ( 'service-utils' ) ,
66 HttpStatus = require ( 'http-status-codes' ) ,
77 log = common . services . log ( "featureService/services/visits" ) ,
8- pg = require ( 'pg' ) ,
9- process = require ( 'process' ) ,
8+ postgres = require ( './postgres' ) ,
109 ServiceError = common . utils . ServiceError ,
11- url = require ( 'url' ) ,
1210 uuid = require ( 'uuid/v4' ) ;
1311
1412let featureTablePool ;
@@ -80,27 +78,14 @@ function getByUserId(userId, callback) {
8078}
8179
8280function init ( callback ) {
83- if ( ! process . env . FEATURES_CONNECTION_STRING )
84- return callback ( new ServiceError ( HttpStatus . INTERNAL_SERVER_ERROR , "FEATURES_CONNECTION_STRING configuration not provided as environment variable" ) ) ;
81+ postgres . init ( function ( err , pool ) {
82+ if ( err ) {
83+ return callback ( err ) ;
84+ }
8585
86- // POSTGRES CONNECTION CODE
87-
88- log . info ( 'connecting to features database using: ' + process . env . FEATURES_CONNECTION_STRING ) ;
89-
90- const params = url . parse ( process . env . FEATURES_CONNECTION_STRING ) ;
91- const auth = params . auth . split ( ':' ) ;
92-
93- const config = {
94- user : auth [ 0 ] ,
95- password : auth [ 1 ] ,
96- host : params . hostname ,
97- port : params . port ,
98- database : params . pathname . split ( '/' ) [ 1 ]
99- } ;
100-
101- featureTablePool = new pg . Pool ( config ) ;
102-
103- return callback ( ) ;
86+ featureTablePool = pool ;
87+ return callback ( ) ;
88+ } ) ;
10489}
10590
10691function put ( visits , callback ) {
0 commit comments