mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-09 12:56:07 +08:00
added a function to get last result
This commit is contained in:
parent
a11aef772f
commit
7da9afb557
1 changed files with 12 additions and 0 deletions
|
|
@ -50,6 +50,18 @@ class ResultDAO {
|
|||
return result;
|
||||
}
|
||||
|
||||
static async getLastResult(uid) {
|
||||
let result = await mongoDB()
|
||||
.collection("results")
|
||||
.find({ uid })
|
||||
.sort({ timestamp: -1 })
|
||||
.limit(1)
|
||||
.toArray();
|
||||
result = result[0];
|
||||
if (!result) throw new MonkeyError(404, "No results found");
|
||||
return result;
|
||||
}
|
||||
|
||||
static async getResultByTimestamp(uid, timestamp) {
|
||||
return await mongoDB().collection("results").findOne({ uid, timestamp });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue