From 55dcb54e9a9ac3a5d7f5dc40544a6a98980c884a Mon Sep 17 00:00:00 2001 From: Ianyourgod Date: Sun, 31 Mar 2024 14:46:38 -0500 Subject: [PATCH] should be all working now --- api/db/UMTests.js | 3 ++- api/db/UserManager.js | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/api/db/UMTests.js b/api/db/UMTests.js index 0af12f3..204170d 100644 --- a/api/db/UMTests.js +++ b/api/db/UMTests.js @@ -396,7 +396,8 @@ async function tests() { let deleteProject = await manager.deleteProject(getProjects[0].id); let getDeletedProject = await manager.getProjectData(getProjects[0].id); - if (getDeletedProject !== null) { + if (getDeletedProject) { + console.log(getDeletedProject); console.log("[ FAIL ]".red, "Failed to delete project"); return false; } diff --git a/api/db/UserManager.js b/api/db/UserManager.js index 2a1c786..01af74c 100644 --- a/api/db/UserManager.js +++ b/api/db/UserManager.js @@ -608,6 +608,7 @@ class UserManager { notes: notes, remix: remix, featured: false, + views: 0, date: Date.now(), lastUpdate: Date.now(), rating: rating @@ -716,6 +717,8 @@ class UserManager { * @async */ async getProjectData(id) { + if (!await this.projectExists(id)) return false; + const tempresult = await this.projects.findOne({id: id}) // add the views, loves, and votes @@ -755,6 +758,7 @@ class UserManager { } this.views.push({id: id, ip: ip}); + await this.projects.updateOne({id: id}, {$inc: {views: 1}}); } async getProjectViews(id) { @@ -885,6 +889,10 @@ class UserManager { */ async deleteProject(id) { await this.projects.deleteOne({id: id}); + + // remove the loves and votes + await this.projectStats.deleteMany({projectId: id}); + fs.rmSync(path.join(__dirname, `./projects/files/project_${id}.pmp`)); fs.rmSync(path.join(__dirname, `./projects/images/project_${id}.png`)); } @@ -1000,7 +1008,7 @@ class UserManager { async projectExists(id) { const result = await this.projects.findOne({id: id}); - return result !== undefined; + return result ? true : false; } /**