added a function to get last result

This commit is contained in:
Miodec 2021-12-30 16:05:32 +01:00
parent a11aef772f
commit 7da9afb557

View file

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