mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-11 22:23:32 +08:00
added userdao function to remove tag pb
This commit is contained in:
parent
ef008758b0
commit
30b1ac269b
1 changed files with 19 additions and 0 deletions
|
@ -60,6 +60,25 @@ class UsersDAO {
|
|||
.collection("users")
|
||||
.updateOne({ uid }, { $pull: { id } });
|
||||
}
|
||||
|
||||
static async removeTagPb(uid, id) {
|
||||
const user = await mongoDB().collection("users").findOne({ uid });
|
||||
if (!user) throw new MonkeyError(404, "User not found");
|
||||
if (
|
||||
user.tags === undefined ||
|
||||
user.tags.filter((t) => t._id === id).length === 0
|
||||
)
|
||||
throw new MonkeyError(404, "Tag not found");
|
||||
return await mongoDB()
|
||||
.collection("users")
|
||||
.updateOne(
|
||||
{
|
||||
uid: uid,
|
||||
"tags._id": id,
|
||||
},
|
||||
{ $pull: { tags: { personalBests } } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UsersDAO;
|
||||
|
|
Loading…
Reference in a new issue