--- a/controllers/controllerV0.js
+++ b/controllers/controllerV0.js
@@ -5,6 +5,7 @@
var database = require('./mysql');
var logger = require('../config/logger.js');
var controllerNotification = require('../backend/notificationManager');
+var smartSystem = require('../backend/smartRuleSystem');
module.exports.registerVapp= function (req, res) {
logger.info("Request type: ",req.method, "Request URL: ", req.originalUrl);
@@ -24,48 +25,26 @@
logger.error(handler);
res.end();
}
-};
-
-/*************************
-Description: Handler to receive new notification
-output type: N/A
-JSON body payload structure
- {
- "emailTo": [
- "string",
- "string"
- ],
- "token": "string",
- "body": [
- {
- "subject" : "stirng",
- "subjectValue" : "string"
- },{
- "subject" : "string",
- "subjectValue" : "string"
- },{
- "subject" : "stirng",
- "subjectValue" : "string"
- }
- ]
- }
-
- */
- module.exports.createNotifications= function (req, res) {
- logger.info("Request type: ",req.method, "Request URL: ", req.originalUrl);
- var handler = "backend.controllers.createNotifications";
- logger.info("Starting: ",handler);
+}
+
+module.exports.createNotifications= function (req, res) {
+ logger.info("Request type: ",req.method, "Request URL: ", req.originalUrl);
+ var handler = "backend.controllers.createNotifications";
+ logger.info("Starting: ",handler);
//Check if request body is not empty
if(Object.keys(req.body).length != 0){
//Check if Token Exists
database.checkIfTokenExists(req.body.token, function(isOK, reason){
if(isOK) {
- controllerNotification.notificationHandler(req.body.body, req.body.emailTo, req.body.token, function(ifOK, reason, notificationsCreated){
+ controllerNotification.notificationHandler(req.body.body, req.body.token, function(ifOK, reason, notificationsCreated){
if(isOK) {
- //execute email based on the reason
- controllerNotification.cronDispatcher(req.body.emailTo,reason);
+ //execute email/http request based on the reason
+ controllerNotification.cronDispatcher(reason);
+ smartSystem.smartRulesHandler();
+ console.log("200 - reason: " + reason);
sendResponse(200, {success: true, reason:reason},"Notification: Success", res);
}else {
+ console.log("500 - reason: " + reason);
sendResponse(500, {success: false, reason: reason},"Notification: "+reason, res);
}
});
@@ -81,7 +60,7 @@
module.exports.createNotificationsRules= function (req, res) {
logger.info("Request type: ",req.method, "Request URL: ", req.originalUrl);
var handler = "backend.controllers.createNotificationsRules";
- logger.info("Starting: ",handler);
+ logger.info("Starting: ",handler);
var response = [];
if(Object.keys(req.body).length != 0){
req.body.forEach(function(eachBody, index){
@@ -91,11 +70,11 @@
response.push({description: eachBody.description, success: true })
}else {
logger.info(handler,data);
- response.push({description: eachBody.description, success: false })
+ response.push({description: eachBody.description, success: false })
}
});
if(req.body.length-1 == index){
- sendResponse(200, {success:true, data:response},"Create Rules: "+response, res);
+ sendResponse(200, {success:true},"Create Rules: "+response, res);
}
})
@@ -103,7 +82,7 @@
logger.error(handler);
res.end();
}
-};
+}
module.exports.getNotifications= function (req, res) {
logger.info("Request type: ",req.method, "Request URL: ", req.originalUrl);
@@ -119,7 +98,7 @@
sendResponse(200, {success: true, data:rows},"Get Notifications: Success",res);
}
});
-};
+}
module.exports.getApps= function (req, res) {
logger.info("Request type:",req.method, "Request URL:", req.originalUrl);
@@ -135,7 +114,7 @@
sendResponse(200, {success: true, data:rows},"Get Vapps: Success",res);
}
});
-};
+}
/*output:
{
@@ -156,7 +135,7 @@
sendResponse(200, {success: true, data:rows},"Get Rules: Success",res);
}
});
-};
+}
module.exports.getStatistics= function (req, res) {
logger.info("Request type:",req.method, "Request URL:", req.originalUrl);
@@ -172,7 +151,7 @@
sendResponse(200, {success: true, data:rows,total},"Get Statistics: Success",res);
}
});
-};
+}
module.exports.deleteVapp= function (req, res) {
logger.info("Request type:",req.method, "Request URL:", req.originalUrl);
@@ -185,10 +164,10 @@
sendResponse(500, {success:false, data:data},"Delete Vapp: "+data,res);
}else {
logger.info(handler,data);
- sendResponse(200, {success: true, data:data},"Delete Vapp: Success",res);
- }
- });
-};
+ sendResponse(200, {success: true},"Delete Vapp: Success",res);
+ }
+ });
+}
module.exports.deleteRule= function (req, res) {
logger.info("Request type:",req.method, "Request URL:", req.originalUrl);
@@ -201,10 +180,10 @@
sendResponse(500, {success:false, data:data},"Delete Rule: "+data,res);
}else {
logger.info(handler,data);
- sendResponse(200, {success: true, data:data},"Delete Rule: Success",res);
- }
- });
-};
+ sendResponse(200, {success: true},"Delete Rule: Success",res);
+ }
+ });
+}
module.exports.editRule= function (req, res) {
logger.info("Request type: ",req.method, "Request URL: ", req.originalUrl);
@@ -219,7 +198,7 @@
sendResponse(200, {success: true, data:data},"Update Rule: Success",res);
}
});
-};
+}
module.exports.getAllRule= function (req, res) {
logger.info("Request type: ",req.method, "Request URL: ", req.originalUrl);
@@ -235,7 +214,7 @@
sendResponse(200, {success: true, data:rows},"Get All Specific Rule: Success",res);
}
});
-};
+}
/*
INPUT: