-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
executable file
·117 lines (99 loc) · 3.42 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var app = require("express")();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var serviceAccount = require('./keys.json');
var firebase = require("firebase");
var morgan = require('morgan');
var bodyParser = require('body-parser');
var port = process.env.PORT || 3000;
var nodemailer = require('nodemailer');
var configuration = require("./configuration.js");
var message = require("./message.js");
var config = { //Setting up database
apiKey: "AIzaSyARk5k9jBvqHHjniavl08r84ReHjYPBSYc",
authDomain: "data-ccd0e.firebaseapp.com",
databaseURL: "https://data-ccd0e.firebaseio.com",
projectId: "data-ccd0e",
storageBucket: "data-ccd0e.appspot.com",
messagingSenderId: "262459432768"
};
firebase.initializeApp(config); //Initializing database
var database = firebase.database();
var bin = database.ref("binMetaData"); //Connecting database which has bin data/information
var users = database.ref("users"); //Connecting database which has users data information
var address = process.argv[2];
var user = database.ref("users");
var readBin = database.ref("binReadings");
var location = database.ref("locations");
var notificationUsers = database.ref("notificationUser");
var notifications = database.ref("notifications");
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
io.origins('*:*');
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json());
//Method that creates the transport and takes of the user who sends the email
var smtpTransport = nodemailer.createTransport({
service: configuration.getService(),
auth: {
user: configuration.getUser(),
pass: configuration.getPassword()
}
});
var msg = {
from: message.getFrom(),
subject: message.getSubject(),
//text: message.getText(),
status: message.getStatus()
}
app.post("/api/pushNotificationUser", function(req,res){
var data = req.body;
//console.log(data);
notificationUser.push(data);
});
//database.ref(`notifications`).remove();
database.ref(`notifications`).remove();
////console.log(Date.parse("31 October 2018"));
////console.log("31 October 2018" > "1 November 2018");
/*
//API that stores the users in the notificationUser that will be passed by the admin
app.post("/api/storeUser", function(req,res){
notificationUser.once("value", function(snapshot){
var input = req.body;
var data = snapshot.val();
if(data != null)
{
var keys = Object.keys(data);
}
var keysInput = Object.keys(input);
var userSent = [];
var isNotified;
var count = 0;
for(var i = 0; i < keysInput.length; i++)
{
var k = keysInput[i];
userSent[i] = input[k];
isNotified = input[k].notified;
if(isNotified == "true")
{
notificationUser.push(userSent[i]);
}
else
{
for(var j = 0; j < keys.length; j++)
{
var l = keys[j];
if(data[l].email == input[k].email)
{
database.ref(`notificationUser/${l}`).remove();
}
}
}
}
});
});
*/