Switch to side-by-side view

--- a/backend/notificationManager.js
+++ b/backend/notificationManager.js
@@ -239,53 +239,61 @@
 		eachElem.results.forEach(function(eachResult, resultidx){
 			if(eachResult.success){
 				mysql.getRulesListByRulesID(eachResult.ruleid, function(isOK, ruleslist){
-					if(!isOK){
-						logger.error("getRulesListByRulesID Failed: " + ruleslist);
-					}else{
-						logger.info("getRulesListByRulesID: Success");
-						if(ruleslist[0].notificationType == 0){
-							httprequest.sendHttpRequest(ruleslist[0].hostname, ruleslist[0].port, ruleslist[0].path, ruleslist[0].method, {subject: eachElem.subject, value: eachElem.subjectValue,rule:eachResult.ruleid});
-							//Detect the End of Loop
-							if(reason.length-1 == reasonidx && eachElem.results.length-1 == resultidx){
-								ToSendEmail(thiscron);
-							}
-						}else{
+					if(isOK){
+						if(ruleslist[0].notifyType == "Email"){
 							thiscron[eachResult.notType-1].proceed = true;
-							thiscron[eachResult.notType-1].list.push({subject: eachElem.subject, value: eachElem.subjectValue,rule:eachResult.ruleid});
-							//Detect the End of Loop
-							if(reason.length-1 == reasonidx && eachElem.results.length-1 == resultidx){
-								ToSendEmail(thiscron);
-							}
+							thiscron[eachResult.notType-1].list.push({subject: eachElem.subject, value: eachElem.subjectValue,rule:eachResult.ruleid})
 						}
 					}
+
 				})
 			}
+			//Detect the end of loop
+			if(reason.length-1 == reasonidx && eachElem.results.length-1 == resultidx){
+
+				if(process.env.EMAILON){
+					logger.info(handler,"Email feature is activated");
+					var crontab = require('node-crontab');
+					
+					thiscron.forEach(function(eachCron){
+						if(eachCron.proceed){
+							mysql.getRulesListByRulesID(eachCron.list.rule, function(isOK, ruleslist){
+								if(isOK){
+									emailTo = ruleslist[0].emailTo;
+									logger.info(handler,"Creating scheduled job for notification type",eachCron.type,"Destination list",emailTo,"Email Content",eachCron.list,"Scheduled for day",eachCron.schedule);
+									var jobid=crontab.scheduleJob("* * * "+eachCron.schedule+" * *", function(){
+										email.sendEmail(emailTo, JSON.stringify(eachCron.list));
+									},null,null,false);
+									logger.info(handler,"Scheduled job created with id",jobid);
+								}
+							})
+						}
+						
+					})
+				}else{
+					logger.info(handler, "Email feature is NOT activated");
+				}
+			}
 		})
 	})
 }
 
-//function ToSendEmail(thiscron)
-function ToSendEmail(thiscron){
-	if(process.env.EMAILON){
-		logger.info(handler,"Email feature is activated");
-		var crontab = require('node-crontab');
-
-		thiscron.forEach(function(eachCron){
-			if(eachCron.proceed){
-				mysql.getRulesListByRulesID(eachCron.list.rule, function(isOK, ruleslist){
+//function cronDispatcherHTTPRequest(reason)
+module.exports.cronDispatcherHTTPRequest = function(reason){
+	var handler = "cronDispatcherHTTPRequest";
+
+	reason.forEach(function(eachElem, reasonidx){
+		eachElem.results.forEach(function(eachResult, resultidx){
+			if(eachResult.success){
+				mysql.getRulesListByRulesID(eachResult.ruleid, function(isOK, ruleslist){
 					if(isOK){
-						emailTo = ruleslist[0].emailTo;
-						logger.info(handler,"Creating scheduled job for notification type",eachCron.type,"Destination list",emailTo,"Email Content",eachCron.list,"Scheduled for day",eachCron.schedule);
-						var jobid=crontab.scheduleJob("* * * "+eachCron.schedule+" * *", function(){
-							email.sendEmail(emailTo, JSON.stringify(eachCron.list));
-						},null,null,false);
-						logger.info(handler,"Scheduled job created with id",jobid);
+						if(ruleslist[0].notifyType == "HTTP Request"){
+							httprequest.sendHttpRequest(ruleslist.hostname, ruleslist.port, ruleslist.path, ruleslist.method, {subject: eachElem.subject, value: eachElem.subjectValue,rule:eachResult.ruleid});
+						}
 					}
+
 				})
 			}
-
 		})
-	}else{
-		logger.info(handler, "Email feature is NOT activated");
-	}
+	})
 }