From 5c420440adae7a5d600b3bf49cab35dc558b518d Mon Sep 17 00:00:00 2001
From: Oguntola Joshua <101347375+ExtranoDev@users.noreply.github.com>
Date: Thu, 21 Sep 2023 17:27:30 +0100
Subject: [PATCH] Revert "Added config "
---
.husky/pre-commit | 4 +-
config/nodemailerConfig.js | 18 -----
controllers/emailConfirmationController.js | 91 ----------------------
errors/custom-errors.js | 11 +++
package-lock.json | 9 ---
package.json | 1 -
6 files changed, 13 insertions(+), 121 deletions(-)
delete mode 100644 config/nodemailerConfig.js
create mode 100644 errors/custom-errors.js
diff --git a/.husky/pre-commit b/.husky/pre-commit
index 29a5bf0a..57fd229e 100644
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
-# npm run lint
-# npm run format
+npm run lint
+npm run format
diff --git a/config/nodemailerConfig.js b/config/nodemailerConfig.js
deleted file mode 100644
index f17192dc..00000000
--- a/config/nodemailerConfig.js
+++ /dev/null
@@ -1,18 +0,0 @@
-const nodemailer = require('nodemailer');
-const dotenv = require('dotenv');
-
-dotenv.config();
-
-exports.transport = nodemailer.createTransport({
- service: 'gmail',
- host: 'smtp.gmail.com',
- port: 465,
- secure: true,
- auth: {
- user: 'team.lightning.hng@gmail.com', //This should be in environment variable
- pass: 'rfnx htnk iaus yapv', //This should be in environment variable
- },
- tls: {
- rejectUnauthorized: false,
- },
-});
diff --git a/controllers/emailConfirmationController.js b/controllers/emailConfirmationController.js
index ddead37c..8b137891 100644
--- a/controllers/emailConfirmationController.js
+++ b/controllers/emailConfirmationController.js
@@ -1,92 +1 @@
-// import bcrypt from "bcryptjs"
-const dotenv = require('dotenv');
-const { transport } = require('../config/nodemailerConfig.js');
-dotenv.config();
-const teamMail = process.env.TEAM_MAIL;
-
-const issueOtp = async (userId, email) => {
- const otp = `${Math.floor(1000 + Math.random() * 9000)}`;
- const saltRounds = 12; //This should be in environment variable
-
- // const hashedOTP = await bcrypt.hash(otp, saltRounds);
-
- //Save hased otp with userId and email for confirmation purposes
- //Hased OTP should be saved to db for confirmation later,then deleted upon successful authentication
-
- return {
- userOtp: otp,
- timeLeft: `1 hour`,
- };
-};
-
-const otpMessage = (otp, timeLeft) => {
- const template = `
-
-
Welcome to XXXX 2.0
-
-
Your OTP is ${otp}
- It expires in ${timeLeft}
-
-
- `;
- return template;
-};
-
-// Function to send email with otp code
-const sendEmail = async (email, message) => {
- const mailOptions = {
- from: 'team.lightning.hng@gmail.com', //This should be in environement variable
- subject: 'Verify your email',
- to: email,
- html: message,
- };
-
- return new Promise((resolve, reject) => {
- transport.sendMail(mailOptions, (err, info) => {
- if (err) reject(err);
- resolve(info);
- });
- });
-};
-
-const sendUserOtp = async (userId, email) => {
- try {
- if (!userId || !email) {
- return {
- status: false,
- message: `User details cannot be empty`,
- };
- }
-
- //generate a new otp
- const otp = await issueOtp(userId, email);
- const message = otpMessage(otp.userOtp, otp.timeLeft);
-
- //send mail with otp details
- await sendEmail(email, message);
-
- return {
- status: true,
- message: 'otp sent successfully',
- data: null,
- };
- } catch (error) {
- console.log(error);
- return {
- status: false,
- message: `internal server error`,
- };
- }
-};
-
-module.exports = {
- issueOtp,
- otpMessage,
- sendEmail,
- sendUserOtp,
-};
-
-//call this function to test controller
-// sendUserOtp('1','test@example.com')
diff --git a/errors/custom-errors.js b/errors/custom-errors.js
new file mode 100644
index 00000000..759c4c7b
--- /dev/null
+++ b/errors/custom-errors.js
@@ -0,0 +1,11 @@
+class CustomErrorClass extends Error {
+ constructor(message, statusCode) {
+ super(message);
+ this.statusCode = statusCode;
+ }
+}
+
+const createCustomError = (message, statusCode) =>
+ new CustomErrorClass(message, statusCode);
+
+module.exports = { createCustomError, CustomErrorClass };
diff --git a/package-lock.json b/package-lock.json
index 8ece5842..7f636b5c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -17,7 +17,6 @@
"jsonwebtoken": "^9.0.2",
"morgan": "^1.10.0",
"mysql2": "^3.6.1",
- "nodemailer": "^6.9.5",
"sequelize": "^6.33.0"
},
"devDependencies": {
@@ -3479,14 +3478,6 @@
}
}
},
- "node_modules/nodemailer": {
- "version": "6.9.5",
- "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.5.tgz",
- "integrity": "sha512-/dmdWo62XjumuLc5+AYQZeiRj+PRR8y8qKtFCOyuOl1k/hckZd8durUUHs/ucKx6/8kN+wFxqKJlQ/LK/qR5FA==",
- "engines": {
- "node": ">=6.0.0"
- }
- },
"node_modules/nodemon": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz",
diff --git a/package.json b/package.json
index f328205c..ca2b0d97 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,6 @@
"jsonwebtoken": "^9.0.2",
"morgan": "^1.10.0",
"mysql2": "^3.6.1",
- "nodemailer": "^6.9.5",
"sequelize": "^6.33.0"
},
"devDependencies": {