From 1db78e4a827b52859bad857aa7d46c4962e9e090 Mon Sep 17 00:00:00 2001 From: Yash Gupta Date: Tue, 17 Oct 2023 13:20:20 -0400 Subject: [PATCH 1/3] backend fixes --- src/server/mongodb/actions/User.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/server/mongodb/actions/User.js b/src/server/mongodb/actions/User.js index d8c278e..a0d962b 100644 --- a/src/server/mongodb/actions/User.js +++ b/src/server/mongodb/actions/User.js @@ -28,13 +28,25 @@ async function deleteUser(id) { return res; } async function createRootUser() { - return await User.create({ - email: "root@boggers.com", - password: await bcrypt.hash("root", 10), - firstName: "boggers", - lastName: "boggers", - access: 2, - }); + try { + const user = await User.create({ + email: "root@boggers.com", + password: await bcrypt.hash("root", 10), + firstName: "boggers", + lastName: "boggers", + access: 2, + emailVerified: true, + }); + + return user; + } catch(error) { + if (error.code === 11000) { + throw new Error("Duplicate email") + } else { + throw new Error("Error is" + error.message) + } + } + } async function createSeedUser(email, password, access) { From da1496e90ace98fc3d473a197af77ad2657efb13 Mon Sep 17 00:00:00 2001 From: Yash Gupta Date: Sat, 28 Oct 2023 12:02:35 -0400 Subject: [PATCH 2/3] changes to error handling --- src/server/mongodb/actions/User.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/mongodb/actions/User.js b/src/server/mongodb/actions/User.js index a0d962b..5ecf36c 100644 --- a/src/server/mongodb/actions/User.js +++ b/src/server/mongodb/actions/User.js @@ -41,9 +41,13 @@ async function createRootUser() { return user; } catch(error) { if (error.code === 11000) { - throw new Error("Duplicate email") + return { + error: "Duplicate email" + } } else { - throw new Error("Error is" + error.message) + return { + error: "Error is" + error.message + } } } From 9298004d63b6690881bcdd3531d6a9990d717172 Mon Sep 17 00:00:00 2001 From: David Pang Date: Sat, 28 Oct 2023 12:17:06 -0400 Subject: [PATCH 3/3] Lint --- src/server/mongodb/actions/User.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/server/mongodb/actions/User.js b/src/server/mongodb/actions/User.js index 5ecf36c..f827dd8 100644 --- a/src/server/mongodb/actions/User.js +++ b/src/server/mongodb/actions/User.js @@ -39,18 +39,17 @@ async function createRootUser() { }); return user; - } catch(error) { + } catch (error) { if (error.code === 11000) { return { - error: "Duplicate email" - } + error: "Duplicate email", + }; } else { return { - error: "Error is" + error.message - } + error: "Error is" + error.message, + }; } } - } async function createSeedUser(email, password, access) {