mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-12 23:20:25 +08:00
added tag verification when setting tags on result
This commit is contained in:
parent
a692e44038
commit
b76df52dee
1 changed files with 9 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
const MonkeyError = require("../handlers/error");
|
||||
const { mongoDB } = require("../init/mongodb");
|
||||
const UserDAO = require("./user");
|
||||
|
||||
class ResultDAO {
|
||||
static async addResult(uid, result) {
|
||||
|
@ -10,6 +11,12 @@ class ResultDAO {
|
|||
static async editResultTags(uid, id, tags) {
|
||||
const result = await mongoDB().collection("result").findOne({ id, uid });
|
||||
if (!result) throw new MonkeyError(404, "Result not found");
|
||||
const userTags = await UserDAO.getTags(uid);
|
||||
let validTags = true;
|
||||
tags.forEach(tagId => {
|
||||
if(!userTags.includes(tagId)) validTags = false;
|
||||
});
|
||||
if (!validTags) throw new MonkeyError(400, "One of the tag id's is not vaild");
|
||||
return await mongoDB()
|
||||
.collection("results")
|
||||
.updateOne({ id, uid }, { $set: { tags } });
|
||||
|
@ -26,8 +33,8 @@ class ResultDAO {
|
|||
end = end ?? 1000;
|
||||
const result = await mongoDB()
|
||||
.collection("result")
|
||||
.find({ id, uid })
|
||||
.sort({ timestamp })
|
||||
.find({ uid })
|
||||
.sort({ timestamp: -1 })
|
||||
.skip(start)
|
||||
.limit(end); // this needs to be changed to later take patreon into consideration
|
||||
if (!result) throw new MonkeyError(404, "Result not found");
|
||||
|
|
Loading…
Reference in a new issue