From 30b1ac269b3eb878f8d4f8c6bc99172bf882c68a Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 8 Jun 2021 23:02:11 +0100 Subject: [PATCH] added userdao function to remove tag pb --- backend/dao/usersDAO.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/dao/usersDAO.js b/backend/dao/usersDAO.js index 1979bfe47..9e6a6f3f3 100644 --- a/backend/dao/usersDAO.js +++ b/backend/dao/usersDAO.js @@ -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;