1
- var plugin = { } ,
1
+ var pluginOb = { } ,
2
2
common = require ( '../../../api/utils/common.js' ) ,
3
3
countlyCommon = require ( '../../../api/lib/countly.common.js' ) ,
4
4
plugins = require ( '../../pluginManager.js' ) ;
5
5
6
- ( function ( plugin ) {
6
+ ( function ( ) {
7
7
8
8
//read api call
9
9
plugins . register ( "/o" , function ( ob ) {
10
10
var params = ob . params ;
11
11
var validate = ob . validateUserForGlobalAdmin ;
12
- if ( params . qstring . method == 'systemlogs' ) {
12
+ if ( params . qstring . method === 'systemlogs' ) {
13
13
var query = { } ;
14
14
if ( typeof params . qstring . query === "string" ) {
15
15
try {
@@ -20,7 +20,7 @@ var plugin = {},
20
20
query = { } ;
21
21
}
22
22
}
23
- if ( params . qstring . sSearch && params . qstring . sSearch != "" ) {
23
+ if ( params . qstring . sSearch && params . qstring . sSearch !== "" ) {
24
24
query . i = { "$regex" : new RegExp ( ".*" + params . qstring . sSearch + ".*" , 'i' ) } ;
25
25
//filter["$text"] = { "$search": "\""+params.qstring.sSearch+"\"" };
26
26
}
@@ -29,51 +29,51 @@ var plugin = {},
29
29
query . ts = countlyCommon . getTimestampRangeQuery ( params , true ) ;
30
30
}
31
31
query . _id = { $ne : "meta_v2" } ;
32
- validate ( params , function ( params ) {
32
+ validate ( params , function ( paramsNew ) {
33
33
var columns = [ "ts" , "u" , "a" , "ip" , "i" ] ;
34
- common . db . collection ( 'systemlogs' ) . count ( { } , function ( err , total ) {
34
+ common . db . collection ( 'systemlogs' ) . count ( { } , function ( err1 , total ) {
35
35
total -- ;
36
36
var cursor = common . db . collection ( 'systemlogs' ) . find ( query ) ;
37
- cursor . count ( function ( err , count ) {
38
- if ( params . qstring . iDisplayStart && params . qstring . iDisplayStart ! = 0 ) {
39
- cursor . skip ( parseInt ( params . qstring . iDisplayStart ) ) ;
37
+ cursor . count ( function ( err2 , count ) {
38
+ if ( paramsNew . qstring . iDisplayStart && parseInt ( paramsNew . qstring . iDisplayStart ) != = 0 ) {
39
+ cursor . skip ( parseInt ( paramsNew . qstring . iDisplayStart ) ) ;
40
40
}
41
- if ( params . qstring . iDisplayLength && params . qstring . iDisplayLength ! = - 1 ) {
42
- cursor . limit ( parseInt ( params . qstring . iDisplayLength ) ) ;
41
+ if ( paramsNew . qstring . iDisplayLength && parseInt ( paramsNew . qstring . iDisplayLength ) != = - 1 ) {
42
+ cursor . limit ( parseInt ( paramsNew . qstring . iDisplayLength ) ) ;
43
43
}
44
- if ( params . qstring . iSortCol_0 && params . qstring . sSortDir_0 ) {
45
- var ob = { } ;
46
- ob [ columns [ params . qstring . iSortCol_0 ] ] = ( params . qstring . sSortDir_0 == "asc" ) ? 1 : - 1 ;
47
- cursor . sort ( ob ) ;
44
+ if ( paramsNew . qstring . iSortCol_0 && paramsNew . qstring . sSortDir_0 ) {
45
+ var obj = { } ;
46
+ obj [ columns [ paramsNew . qstring . iSortCol_0 ] ] = ( paramsNew . qstring . sSortDir_0 = == "asc" ) ? 1 : - 1 ;
47
+ cursor . sort ( obj ) ;
48
48
}
49
49
50
- cursor . toArray ( function ( err , res ) {
51
- if ( err ) {
52
- console . log ( err ) ;
50
+ cursor . toArray ( function ( err3 , res ) {
51
+ if ( err3 ) {
52
+ console . log ( err3 ) ;
53
53
}
54
54
res = res || [ ] ;
55
- common . returnOutput ( params , { sEcho : params . qstring . sEcho , iTotalRecords : total , iTotalDisplayRecords : count , aaData : res } ) ;
55
+ common . returnOutput ( paramsNew , { sEcho : paramsNew . qstring . sEcho , iTotalRecords : total , iTotalDisplayRecords : count , aaData : res } ) ;
56
56
} ) ;
57
57
} ) ;
58
58
} ) ;
59
59
} ) ;
60
60
return true ;
61
61
}
62
- else if ( params . qstring . method == 'systemlogs_meta' ) {
63
- validate ( params , function ( params ) {
62
+ else if ( params . qstring . method === 'systemlogs_meta' ) {
63
+ validate ( params , function ( paramsNew ) {
64
64
//get all users
65
- common . db . collection ( 'members' ) . find ( { } , { username : 1 , email : 1 , full_name : 1 } ) . toArray ( function ( err , users ) {
66
- common . db . collection ( 'systemlogs' ) . findOne ( { _id : "meta_v2" } , { _id : 0 } , function ( err , res ) {
65
+ common . db . collection ( 'members' ) . find ( { } , { username : 1 , email : 1 , full_name : 1 } ) . toArray ( function ( err1 , users ) {
66
+ common . db . collection ( 'systemlogs' ) . findOne ( { _id : "meta_v2" } , { _id : 0 } , function ( err2 , res ) {
67
67
var result = { } ;
68
- if ( ! err && res ) {
68
+ if ( ! err2 && res ) {
69
69
for ( var i in res ) {
70
70
result [ i ] = Object . keys ( res [ i ] ) . map ( function ( arg ) {
71
71
return common . db . decode ( arg ) ;
72
72
} ) ;
73
73
}
74
74
}
75
75
result . users = users || [ ] ;
76
- common . returnOutput ( params , result ) ;
76
+ common . returnOutput ( paramsNew , result ) ;
77
77
} ) ;
78
78
} ) ;
79
79
} ) ;
@@ -112,7 +112,6 @@ var plugin = {},
112
112
} ) ;
113
113
114
114
plugins . register ( "/i/apps/update" , function ( ob ) {
115
- var appId = ob . appId ;
116
115
var data = { } ;
117
116
data . before = { } ;
118
117
data . after = { } ;
@@ -200,7 +199,7 @@ var plugin = {},
200
199
if ( typeof ob . data . before !== "undefined" && typeof ob . data . update !== "undefined" ) {
201
200
var data = { } ;
202
201
for ( var i in ob . data ) {
203
- if ( i != "before" && i != "after" ) {
202
+ if ( i !== "before" && i != = "after" ) {
204
203
data [ i ] = ob . data [ i ] ;
205
204
}
206
205
}
@@ -214,20 +213,26 @@ var plugin = {},
214
213
}
215
214
} ) ;
216
215
217
- //recursive function to compare changes
216
+ /**
217
+ * recursive function to compare changes
218
+ * @param {Object } dataafter - after data values
219
+ * @param {Object } databefore - before data values
220
+ * @param {Object } before - before
221
+ * @param {Object } after - after
222
+ */
218
223
function compareChangesInside ( dataafter , databefore , before , after ) {
219
224
var keys = Object . keys ( after ) ;
220
225
var keys2 = Object . keys ( before ) ;
221
- for ( var i = 0 ; i < keys2 . length ; i ++ ) {
226
+ for ( let i = 0 ; i < keys2 . length ; i ++ ) {
222
227
if ( ! after [ keys2 [ i ] ] ) {
223
228
keys . push ( keys2 [ i ] ) ;
224
229
}
225
230
}
226
231
227
- for ( var i = 0 ; i < keys . length ; i ++ ) {
232
+ for ( let i = 0 ; i < keys . length ; i ++ ) {
228
233
if ( typeof after [ keys [ i ] ] !== "undefined" && typeof before [ keys [ i ] ] !== "undefined" ) {
229
234
if ( typeof after [ keys [ i ] ] === "object" ) {
230
- if ( Array . isArray ( after [ keys [ i ] ] ) && JSON . stringify ( after [ keys [ i ] ] ) != JSON . stringify ( before [ keys [ i ] ] ) ) {
235
+ if ( Array . isArray ( after [ keys [ i ] ] ) && JSON . stringify ( after [ keys [ i ] ] ) !== JSON . stringify ( before [ keys [ i ] ] ) ) {
231
236
databefore [ keys [ i ] ] = before [ keys [ i ] ] ;
232
237
dataafter [ keys [ i ] ] = after [ keys [ i ] ] ;
233
238
}
@@ -240,14 +245,14 @@ var plugin = {},
240
245
}
241
246
242
247
compareChangesInside ( dataafter [ keys [ i ] ] , databefore [ keys [ i ] ] , before [ keys [ i ] ] , after [ keys [ i ] ] ) ;
243
- if ( typeof dataafter [ keys [ i ] ] === "object" && typeof databefore [ keys [ i ] ] === "object" && Object . keys ( dataafter [ keys [ i ] ] ) == 0 && Object . keys ( databefore [ keys [ i ] ] ) == 0 ) {
248
+ if ( typeof dataafter [ keys [ i ] ] === "object" && typeof databefore [ keys [ i ] ] === "object" && ( Object . keys ( dataafter [ keys [ i ] ] ) ) . length === 0 && ( Object . keys ( databefore [ keys [ i ] ] ) ) . length = == 0 ) {
244
249
delete databefore [ keys [ i ] ] ;
245
250
delete dataafter [ keys [ i ] ] ;
246
251
}
247
252
}
248
253
}
249
254
else {
250
- if ( after [ keys [ i ] ] != before [ keys [ i ] ] ) {
255
+ if ( after [ keys [ i ] ] !== before [ keys [ i ] ] ) {
251
256
databefore [ keys [ i ] ] = before [ keys [ i ] ] ;
252
257
dataafter [ keys [ i ] ] = after [ keys [ i ] ] ;
253
258
}
@@ -265,7 +270,12 @@ var plugin = {},
265
270
}
266
271
}
267
272
}
268
-
273
+ /**
274
+ * Function to compare changes
275
+ * @param {Object } data - data object
276
+ * @param {Object } before - before values
277
+ * @param {Object } after - after values
278
+ */
269
279
function compareChanges ( data , before , after ) {
270
280
if ( before && after ) {
271
281
if ( typeof before . _id !== "undefined" ) {
@@ -277,7 +287,13 @@ var plugin = {},
277
287
compareChangesInside ( data . after , data . before , before , after ) ;
278
288
}
279
289
}
280
-
290
+ /**
291
+ * Function to record action
292
+ * @param {Object } params - Default parameters object
293
+ * @param {Object } user - user object
294
+ * @param {String } action - action
295
+ * @param {Object } data - data object
296
+ */
281
297
function recordAction ( params , user , action , data ) {
282
298
var log = { } ;
283
299
log . a = action ;
@@ -291,7 +307,7 @@ var plugin = {},
291
307
}
292
308
if ( user . _id ) {
293
309
log . user_id = user . _id + "" ;
294
- if ( log . u == "" ) {
310
+ if ( log . u === "" ) {
295
311
common . db . collection ( 'members' ) . findOne ( { _id : common . db . ObjectID . createFromHexString ( user . _id ) } , function ( err , res ) {
296
312
if ( ! err && res ) {
297
313
log . u = res . email || res . username ;
@@ -318,7 +334,7 @@ var plugin = {},
318
334
common . db . collection ( 'members' ) . findOne ( query , function ( err , res ) {
319
335
if ( ! err && res ) {
320
336
log . user_id = res . _id + "" ;
321
- if ( log . u == "" ) {
337
+ if ( log . u === "" ) {
322
338
log . u = res . email || res . username ;
323
339
}
324
340
}
@@ -333,6 +349,6 @@ var plugin = {},
333
349
update [ "a." + common . db . encode ( action ) ] = true ;
334
350
common . db . collection ( "systemlogs" ) . update ( { _id : "meta_v2" } , { $set : update } , { upsert : true } , function ( ) { } ) ;
335
351
}
336
- } ( plugin ) ) ;
352
+ } ( pluginOb ) ) ;
337
353
338
- module . exports = plugin ;
354
+ module . exports = pluginOb ;
0 commit comments