-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
78 lines (68 loc) · 2.5 KB
/
app.js
File metadata and controls
78 lines (68 loc) · 2.5 KB
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
var express = require("express");
var path = require("path");
var alexa = require("alexa-app");
var mongoose = require('mongoose');
var notification = require('./models/notification');
var session = require('./models/sessions');
var interaction = require('./models/interaction');
var deal = require('./models/deals');
var bodyParser = require('body-parser');
var async = require('async');
var PORT = process.env.PORT || 8080;
var app = express();
// Create the database connection
mongoose.connect('mongodb://139.59.20.225/alexa');
mongoose.connection.on('connected', function () { console.log('Mongoose default connection open '); });
mongoose.connection.on('error', function (err) { console.log('Mongoose default connection error'); });
mongoose.connection.on('disconnected', function () { console.log('Mongoose default connection disconnected'); });
var alexa = new alexa.app("alexa");
app.use(bodyParser.json())
app.use(express.static('src'))
app.use('/bower_components', express.static(path.join(__dirname, 'bower_components')))
app.set("view engine", "ejs");
var alexa = require('./alexa/index.js')(app, alexa);
app.post('/notification', (req, res) => {
notification.create({
message: req.body.message
}, function (err, notification) {
res.send(notification);
});
});
app.get('/notifications', (req, res) => {
notification.find({}, {}, { sort: { 'createdAt': -1 } }, function (err, notifications) {
res.send(notifications);
});
});
app.get('/users', (req, res) => {
session.find({}, {}, { sort: { 'createdAt': -1 } }, function (err, notifications) {
res.send(notifications);
});
});
app.get('/dashboard', (req, res) => {
async.parallel({
session: function (callback) {
session.count({}, function (err, data) {
callback(err, data);
});
},
notification: function (callback) {
notification.count({}, function (err, data) {
callback(err, data);
});
},
interaction: function (callback) {
interaction.findOne({}, {}, {}, function (err, interaction) {
var data = interaction.seq;
callback(err, data);
});
},
deal: function (callback) {
deal.count({}, function (err, data) {
callback(err, data);
});
}
}, function (err, results) {
res.send(results);
});
});
app.listen(PORT, () => console.log("Listening on port " + PORT + "."));