Added ranklist

This commit is contained in:
mrfry 2020-10-23 11:59:52 +02:00
parent 17526a14de
commit 13a18c3fd8

View file

@ -43,6 +43,7 @@ const usersDbBackupPath = 'data/dbs/backup'
const quickVoteResultsDir = 'stats/qvote'
const quickVotes = 'stats/qvote/votes.json'
const testUsersFile = 'data/testUsers.json'
const idStatFile = 'stats/idstats'
// other constants
const maxVeteranPwGetCount = 10
@ -161,6 +162,32 @@ function GetApp() {
// -------------------------------------------------------------
app.get('/ranklist', (req, res) => {
const user = req.session.user
const data = utils.ReadJSON(idStatFile)
const list = []
Object.keys(data).forEach((key) => {
list.push({
userId: parseInt(key),
...data[key],
})
})
if (list.length === 0) {
res.json({
msg: 'There are no users in the stats db :c',
})
return
}
res.json({
list: list,
selfuserId: user.id,
})
})
app.get('/quickvote', (req, res) => {
const key = req.query.key
const val = req.query.val