From 463a48f33abf2c41c7130940d92c20490f6ddba7 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 3 Aug 2019 12:04:22 -0400 Subject: [PATCH] Added totals api endpoint --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 079ccc6..821e4c5 100644 --- a/index.js +++ b/index.js @@ -325,6 +325,21 @@ app.get('/api/getTopUsers', function (req, res) { }); }); +//send out totals +//send the total submissions, total views and total minutes saved +app.get('/api/getTotalStats', function (req, res) { + db.prepare("SELECT COUNT(*) as totalSubmissions, SUM(views) as viewCount, SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes").get(function(err, row) { + if (row != null) { + //send this result + res.send({ + viewCount: row.viewCount, + totalSubmissions: row.totalSubmissions, + minutesSaved: row.minutesSaved + }); + } + }); +}); + app.get('/database.db', function (req, res) { res.sendFile("./databases/sponsorTimes.db", { root: __dirname }); });