From b1d16cab39fd0d8c78363ff57a6f61fc0ed17084 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Tue, 17 Oct 2023 12:24:18 +0100 Subject: [PATCH] remove promise.all from closeDatabaseHelper --- backend/src/helpers/database.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/backend/src/helpers/database.ts b/backend/src/helpers/database.ts index 4780be346..611e941f5 100644 --- a/backend/src/helpers/database.ts +++ b/backend/src/helpers/database.ts @@ -14,7 +14,7 @@ export const initDatabaseHelper = async ({ }) => { try { await mongoose.connect(mongoURL); - + // allow empty strings to pass the required validator mongoose.Schema.Types.String.checkRequired(v => typeof v === "string"); @@ -31,14 +31,10 @@ export const initDatabaseHelper = async ({ * Close database conection */ export const closeDatabaseHelper = async () => { - return Promise.all([ - new Promise((resolve) => { - if (mongoose.connection && mongoose.connection.readyState == 1) { - mongoose.connection.close() - .then(() => resolve("Database connection closed")); - } else { - resolve("Database connection already closed"); - } - }), - ]); -} \ No newline at end of file + if (mongoose.connection && mongoose.connection.readyState === 1) { + await mongoose.connection.close(); + return "Database connection closed"; + } else { + return "Database connection already closed"; + } +}; \ No newline at end of file