From 3f55bfea22167b9d9635b2e3b6bfec8a9812ef96 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 24 Sep 2019 18:29:06 -0400 Subject: [PATCH] Added user based time saved endpoint. --- index.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/index.js b/index.js index d3def07..f0d001c 100644 --- a/index.js +++ b/index.js @@ -548,6 +548,37 @@ app.get('/api/getViewsForUser', function (req, res) { }); }); +//Gets all the saved time added up (views * sponsor length) for one userID +//Useful to see how much one user has contributed +//In minutes +app.get('/api/getSavedTimeForUser', function (req, res) { + let userID = req.query.userID; + + if (userID == undefined) { + //invalid request + res.sendStatus(400); + return; + } + + //hash the userID + userID = getHash(userID); + + //up the view count by one + db.prepare("SELECT SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes WHERE userID = ?").get(userID, function(err, row) { + if (err) console.log(err); + + console.log(userID) + + if (row.minutesSaved != null) { + res.send({ + timeSaved: row.minutesSaved + }); + } else { + res.sendStatus(404); + } + }); +}); + app.get('/api/getTopUsers', function (req, res) { let sortType = req.query.sortType;