diff --git a/backend/dao/user.js b/backend/dao/user.js index abfa6c645..86e4ebcef 100644 --- a/backend/dao/user.js +++ b/backend/dao/user.js @@ -1,8 +1,8 @@ const MonkeyError = require("../handlers/error"); const { mongoDB } = require("../init/mongodb"); +const { ObjectID } = require("mongodb"); const { checkAndUpdatePb } = require("../handlers/pb"); const { updateAuthEmail } = require("../handlers/auth"); -const uuid = require("uuid"); class UsersDAO { static async addUser(name, email, uid) { @@ -53,12 +53,12 @@ class UsersDAO { } static async addTag(uid, name) { - let id = uuid.v4(); + let _id = ObjectID(); await mongoDB() .collection("users") - .updateOne({ uid }, { $push: { tags: { id, name } } }); + .updateOne({ uid }, { $push: { tags: { _id, name } } }); return { - id, + _id, name, }; } @@ -69,12 +69,12 @@ class UsersDAO { return user.tags; } - static async editTag(uid, id, name) { + static async editTag(uid, _id, name) { 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 + user.tags.filter((t) => t._id == _id).length === 0 ) throw new MonkeyError(404, "Tag not found"); return await mongoDB() @@ -82,18 +82,18 @@ class UsersDAO { .updateOne( { uid: uid, - "tags.id": id, + "tags._id": ObjectID(_id), }, { $set: { "tags.$.name": name } } ); } - static async removeTag(uid, id) { + static async removeTag(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 + user.tags.filter((t) => t._id == _id).length === 0 ) throw new MonkeyError(404, "Tag not found"); return await mongoDB() @@ -101,18 +101,18 @@ class UsersDAO { .updateOne( { uid: uid, - "tags.id": id, + "tags._id": ObjectID(_id), }, - { $pull: { tags: { id } } } + { $pull: { tags: { _id: ObjectID(_id) } } } ); } - static async removeTagPb(uid, 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 + user.tags.filter((t) => t._id == _id).length === 0 ) throw new MonkeyError(404, "Tag not found"); return await mongoDB() @@ -120,7 +120,7 @@ class UsersDAO { .updateOne( { uid: uid, - "tags.id": id, + "tags._id": ObjectID(_id), }, { $set: { "tags.$.personalBests": {} } } ); @@ -197,7 +197,7 @@ class UsersDAO { let tagsToCheck = []; user.tags.forEach((tag) => { - if (tags.includes(tag.id)) { + if (tags.includes(tag._id)) { tagsToCheck.push(tag); } }); @@ -218,11 +218,11 @@ class UsersDAO { wpm ); if (tagpb.isPb) { - ret.push(tag.id); + ret.push(tag._id); await mongoDB() .collection("users") .updateOne( - { uid, "tags.id": tag.id }, + { uid, "tags._id": ObjectID(tag._id) }, { $set: { "tags.$.personalBests": tagpb.obj } } ); } diff --git a/src/js/account.js b/src/js/account.js index b4d306f6f..f7e7e69f0 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -233,7 +233,7 @@ function loadMoreLines(lineIndex) { if (result.tags !== undefined && result.tags.length > 0) { result.tags.forEach((tag) => { DB.getSnapshot().tags.forEach((snaptag) => { - if (tag === snaptag.id) { + if (tag === snaptag._id) { tagNames += snaptag.name + ", "; } }); diff --git a/src/js/account/result-filters.js b/src/js/account/result-filters.js index b85a32bd5..03c87ab3f 100644 --- a/src/js/account/result-filters.js +++ b/src/js/account/result-filters.js @@ -99,7 +99,7 @@ export function getFilter(group, filter) { export function loadTags(tags) { tags.forEach((tag) => { - defaultResultFilters.tags[tag.id] = true; + defaultResultFilters.tags[tag._id] = true; }); } @@ -305,7 +305,7 @@ export function updateTags() { DB.getSnapshot().tags.forEach((tag) => { $( ".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons" - ).append(`
`); + ).append(` `); }); } else { $(".pageAccount .content .filterButtons .buttonsAndTitle.tags").addClass( @@ -412,7 +412,7 @@ $(".pageAccount .topFilters .button.currentConfigFilter").click((e) => { DB.getSnapshot().tags.forEach((tag) => { if (tag.active === true) { filters["tags"]["none"] = false; - filters["tags"][tag.id] = true; + filters["tags"][tag._id] = true; } }); diff --git a/src/js/commandline-lists.js b/src/js/commandline-lists.js index 8294b1a44..ca34d6d0e 100644 --- a/src/js/commandline-lists.js +++ b/src/js/commandline-lists.js @@ -227,12 +227,12 @@ export function updateTagCommands() { } commandsTags.list.push({ - id: "toggleTag" + tag.id, + id: "toggleTag" + tag._id, noIcon: true, display: dis, sticky: true, exec: () => { - TagController.toggle(tag.id); + TagController.toggle(tag._id); TestUI.updateModesNotice(); let txt = tag.name; @@ -243,14 +243,14 @@ export function updateTagCommands() { } if (Commandline.isSingleListCommandLineActive()) { $( - `#commandLine .suggestions .entry[command='toggleTag${tag.id}']` + `#commandLine .suggestions .entry[command='toggleTag${tag._id}']` ).html( `