@@ -56,7 +56,8 @@ auditTrailService.insertAuditTrail = function insertAuditTrail(auditDetails,audi
5656 user : actionObj . catUser ,
5757 startedOn : new Date ( ) . getTime ( ) ,
5858 providerType : auditDetails . providerType ,
59- action : actionObj . action
59+ action : actionObj . action ,
60+ gitHubId : auditDetails . gitHubId
6061 } ;
6162 if ( actionObj . auditType === 'BOTOLD' || actionObj . auditType === 'BOT' ) {
6263 auditTrailObj . auditTrailConfig = auditTrailConfig ;
@@ -663,8 +664,40 @@ auditTrailService.getAuditTrail = function getAuditTrail(query, callback) {
663664 if ( query . type && query . type == 'snow' ) {
664665 queryObj . queryObj [ '$and' ] . push ( { auditId :{ $in :snowbotsids } } )
665666 }
666-
667- auditTrail . getAuditTrailList ( queryObj , next ) ;
667+ if ( query . auditForDashboard == "true" && query . type == 'snow' ) {
668+ var gitHubQuery = {
669+ "isDefault" : 'true'
670+ } ;
671+ gitHubModel . getGitRepository ( gitHubQuery , '' , ( err , res ) => {
672+ if ( ! err && res . length > 0 ) {
673+ queryObj . queryObj [ '$and' ] . push ( { gitHubId : res [ 0 ] . _id . toString ( ) } )
674+ auditTrail . getAuditTrailList ( queryObj , next ) ;
675+ }
676+ else {
677+ logger . error ( "Default Github account not found for bot summary" ) ;
678+ queryObj . queryObj [ '$and' ] . push ( { gitHubId : '' } )
679+ auditTrail . getAuditTrailList ( queryObj , next ) ;
680+ }
681+ } ) ;
682+ }
683+ if ( query . auditForDashboard == "true" ) {
684+ var gitHubQuery = {
685+ "isDefault" : 'true'
686+ } ;
687+ gitHubModel . getGitRepository ( gitHubQuery , '' , ( err , res ) => {
688+ if ( ! err && res . length > 0 ) {
689+ queryObj . queryObj [ '$and' ] . push ( { gitHubId : res [ 0 ] . _id . toString ( ) } )
690+ auditTrail . getAuditTrailList ( queryObj , next ) ;
691+ }
692+ else {
693+ logger . error ( "Default Github account not found for bot summary" ) ;
694+ queryObj . queryObj [ '$and' ] . push ( { gitHubId : '' } )
695+ auditTrail . getAuditTrailList ( queryObj , next ) ;
696+ }
697+ } ) ;
698+ } else {
699+ auditTrail . getAuditTrailList ( queryObj , next ) ;
700+ }
668701 } ,
669702 function ( auditTrailList , next ) {
670703 apiUtil . paginationResponse ( auditTrailList , reqData , next ) ;
@@ -1143,7 +1176,23 @@ auditTrailService.getBotSummary = function getBotSummary(queryParam, BOTSchema,
11431176 } )
11441177 }
11451178 } ,
1146- function ( botsList , next ) {
1179+ function ( botsList , next ) {
1180+ var gitHubquery = {
1181+ "isDefault" : 'true'
1182+ } ;
1183+ var gitHubIdData ;
1184+ gitHubModel . getGitRepository ( gitHubquery , '' , ( err , res ) => {
1185+ if ( ! err && res . length > 0 ) {
1186+ gitHubIdData = res [ 0 ] . _id . toString ( ) ;
1187+ next ( null , botsList , gitHubIdData ) ;
1188+ }
1189+ else {
1190+ logger . error ( "Default Github account not found for bot summary" ) ;
1191+ next ( null , botsList , '' ) ;
1192+ }
1193+ } ) ;
1194+ } ,
1195+ function ( botsList , gitHubIdData , next ) {
11471196 var totalBots = botsList . length ;
11481197 var botIdList = [ ] ;
11491198 var snowBotId = [ ] ;
@@ -1174,9 +1223,10 @@ auditTrailService.getBotSummary = function getBotSummary(queryParam, BOTSchema,
11741223 querymatch [ 'date' ] = { $gte :sdt , $lte :edt }
11751224 snowQueryMatch [ 'date' ] = { $gte :sdt , $lte :edt }
11761225 }
1177- querymatch [ "botID" ] = { "$in" :botIdList } ;
1226+ querymatch [ "botID" ] = { "$in" :botIdList } ;
11781227 snowQueryMatch [ "botID" ] = { "$in" :snowBotId } ;
1179-
1228+ snowQueryMatch [ "gitHubId" ] = gitHubIdData ;
1229+ querymatch [ "gitHubId" ] = gitHubIdData ;
11801230 query . push ( { $match :querymatch } )
11811231 snowQuery . push ( { $match :snowQueryMatch } )
11821232 query . push ( {
@@ -1377,3 +1427,24 @@ function convertMS( milliseconds ) {
13771427 seconds : seconds
13781428 } ;
13791429}
1430+
1431+ function getDefaultGithub ( callback ) {
1432+ var gitHubquery = {
1433+ "isDefault" : 'true'
1434+ } ;
1435+ var gitHubIdData ;
1436+ gitHubModel . getGitRepository ( gitHubquery , '' , ( err , res ) => {
1437+ if ( ! err && res . length > 0 ) {
1438+ gitHubIdData = res [ 0 ] . _id . toString ( ) ;
1439+ logger . info ( "GITHUBIDD" , gitHubIdData . toString ( ) ) ;
1440+ //querymatch["gitHubId"] = gitHubIdData.toString();
1441+ //callback(null, gitHubIdData);
1442+ //return gitHubIdData.toString()
1443+ //query["gitHubId"] = gitHubIdData.toString();
1444+ //filterQuery['gitHubId'] = res[0]._id;
1445+ }
1446+ else {
1447+ logger . error ( "Default Github account not found for bot summary" ) ;
1448+ }
1449+ } ) ;
1450+ }
0 commit comments