From f52e8749007ea3e73257294399580df9b88c673a Mon Sep 17 00:00:00 2001 From: Ianyourgod Date: Mon, 26 Feb 2024 16:10:59 -0600 Subject: [PATCH] fix failing --- api/db/UMTests.js | 14 +++++++++++++- api/db/UserManager.js | 15 +++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/api/db/UMTests.js b/api/db/UMTests.js index c961fa8..8e730d2 100644 --- a/api/db/UMTests.js +++ b/api/db/UMTests.js @@ -1,11 +1,13 @@ const UserManager = require('./UserManager'); +const prompt = require('prompt-sync')(); const colors = require('colors'); -const understands = process.argv.includes("-u") || +let understands = process.argv.includes("-u") || process.argv.includes("--understands"); async function tests() { + const manager = new UserManager(); await manager.init(); @@ -393,6 +395,16 @@ async function tests() { (async () => { + if (!understands) { + let pmt = prompt("This will reset the database, are you sure? (Y/n) "); + if (typeof pmt !== "string" || + pmt === "n" + ) { + process.exit(0); + } + understands = true; + } + let result = await tests(); if (result) { console.log("[ PASS ]".green, "All tests passed"); diff --git a/api/db/UserManager.js b/api/db/UserManager.js index 41b4c2f..0166ac1 100644 --- a/api/db/UserManager.js +++ b/api/db/UserManager.js @@ -55,14 +55,21 @@ class UserManager { */ async reset(understands = false) { if (!understands) { - if (prompt("This deletes ALL DATA. Are you sure? (Y/n) ") === "n") - return; + let unde = prompt("This deletes ALL DATA. Are you sure? (Y/n) ") + if ( + typeof unde !== "string" + ) { + return; + } + console.log(typeof unde) } await this.users.deleteMany({}); await this.reports.deleteMany({}); await this.projects.deleteMany({}); - fs.rmSync(path.join(__dirname, "projects/files"), { recursive: true, force: true }); - fs.rmSync(path.join(__dirname, "projects/images"), { recursive: true, force: true }); + if (fs.existsSync(path.join(__dirname, "projects/files")) && fs.existsSync(path.join(__dirname, "projects/images"))) { + fs.rmSync(path.join(__dirname, "projects/files"), { recursive: true, force: true }); + fs.rmSync(path.join(__dirname, "projects/images"), { recursive: true, force: true }); + } fs.mkdirSync(path.join(__dirname, "projects/files")); fs.mkdirSync(path.join(__dirname, "projects/images")); }