Fetch top ranking
This commit is contained in:
parent
a575d447f9
commit
0c60b4ef26
4 changed files with 48 additions and 2 deletions
|
|
@ -40,6 +40,14 @@ class Database {
|
|||
await this.db.write()
|
||||
}
|
||||
}
|
||||
|
||||
getTop(amount = 15) {
|
||||
return this.db.data.users
|
||||
.filter(user => user.record)
|
||||
.map(user => { return { name: user.name, record: user.record } })
|
||||
.sort((a, b) => a.record > b.record ? -1 : 1)
|
||||
.slice(0, amount)
|
||||
}
|
||||
}
|
||||
|
||||
export default new Database
|
||||
|
|
|
|||
|
|
@ -84,6 +84,13 @@ app.post("/record", protect, neededArguments(['points', 'shoots', 'time']), jg,
|
|||
})
|
||||
})
|
||||
|
||||
app.get("/top", (req, res) => {
|
||||
res.json({
|
||||
status: "ok",
|
||||
records: db.getTop()
|
||||
})
|
||||
})
|
||||
|
||||
app.use(function (err, req, res, next) {
|
||||
if (err.name === 'UnauthorizedError') {
|
||||
res.status(401).send('invalid token...');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue