@@ -12,6 +12,7 @@ var reportsInstance = {},
12
12
countlyCommon = require ( '../../../api/lib/countly.common.js' ) ,
13
13
localize = require ( '../../../api/utils/localization.js' ) ,
14
14
common = require ( '../../../api/utils/common.js' ) ,
15
+ log = require ( '../../../api/utils/log' ) ( 'reports:reports' ) ,
15
16
versionInfo = require ( '../../../frontend/express/version.info' ) ;
16
17
17
18
versionInfo . page = ( ! versionInfo . title ) ? "https://count.ly" : null ;
@@ -80,12 +81,20 @@ var metrics = {
80
81
* @param {func } cb - callback function
81
82
*/
82
83
function findMember ( cb ) {
83
- db . collection ( 'members' ) . findOne ( { _id : db . ObjectID ( report . user ) } , function ( err , member ) {
84
- if ( err ) {
85
- return cb ( err ) ;
84
+ db . collection ( 'members' ) . findOne ( { _id : db . ObjectID ( report . user ) } , function ( err1 , member ) {
85
+ if ( ! err1 && member ) {
86
+ return cb ( null , member ) ;
86
87
}
87
88
88
- return cb ( null , member ) ;
89
+ db . collection ( 'members' ) . findOne ( { global_admin : true } , function ( err2 , globalAdmin ) {
90
+ if ( ! err2 && globalAdmin ) {
91
+ log . d ( "Report user not found. Updating it to the global admin." ) ;
92
+ report . user = globalAdmin . _id ;
93
+ return cb ( null , globalAdmin ) ;
94
+ }
95
+
96
+ return cb ( err2 ) ;
97
+ } ) ;
89
98
} ) ;
90
99
}
91
100
/**
@@ -242,7 +251,7 @@ var metrics = {
242
251
}
243
252
}
244
253
if ( err || ! data [ 0 ] ) {
245
- return callback ( "No data to report " , { report : report } ) ;
254
+ return callback ( "Report user not found. " , { report : report } ) ;
246
255
}
247
256
248
257
var member = data [ 0 ] ;
0 commit comments