mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-12 23:20:25 +08:00
added some results dao
This commit is contained in:
parent
f2f9201acb
commit
871273c455
1 changed files with 38 additions and 0 deletions
38
backend/dao/resultDAO.js
Normal file
38
backend/dao/resultDAO.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
const MonkeyError = require("../handlers/error");
|
||||
const { mongoDB } = require("../init/mongodb");
|
||||
|
||||
class ResultDAO {
|
||||
static async addResult(uid, result) {
|
||||
if (result.uid === undefined) result.uid = uid;
|
||||
return await mongoDB().collection("results").insertOne(result);
|
||||
}
|
||||
|
||||
static async editResultTags(uid, id, tags) {
|
||||
const result = await mongoDB().collection("result").findOne({ id, uid });
|
||||
if (!result) throw new MonkeyError(404, "Result not found");
|
||||
return await mongoDB()
|
||||
.collection("results")
|
||||
.updateOne({ id, uid }, { $set: { tags } });
|
||||
}
|
||||
|
||||
static async getResult(uid, id) {
|
||||
const result = await mongoDB().collection("result").findOne({ id, uid });
|
||||
if (!result) throw new MonkeyError(404, "Result not found");
|
||||
return result;
|
||||
}
|
||||
|
||||
static async getResults(uid, start, end) {
|
||||
start = start ?? 0;
|
||||
end = end ?? 1000;
|
||||
const result = await mongoDB()
|
||||
.collection("result")
|
||||
.find({ id, uid })
|
||||
.sort({ timestamp })
|
||||
.skip(start)
|
||||
.limit(end); // this needs to be changed to later take patreon into consideration
|
||||
if (!result) throw new MonkeyError(404, "Result not found");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ResultDAO;
|
Loading…
Reference in a new issue