Added user based time saved endpoint.

This commit is contained in:
Ajay Ramachandran 2019-09-24 18:29:06 -04:00
parent 6ae8001b79
commit 3f55bfea22

View file

@ -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;