// controllers/userController.js const User = require("../models/User"); const Products = require("../models/Product"); const jwt = require("jsonwebtoken"); const bcrypt = require("bcrypt"); const otpGenerator = require("otp-generator"); const nodemailer = require("nodemailer"); const fs = require("fs"); const path = require("path"); const { getUser } = require("../config/getUser"); // const registerUser = async (req, res) => { // try { // // Create user in the database // const request = req.body; // No need to use await here // const UserCount = await User.countDocuments(); // const existingUser = await User.findOne({ email: request.email }); // if (existingUser) { // return res.status(400).json({ // UserCount, // success: false, // message: 'User With This Email Already Exists', // }); // } // const otp = otpGenerator.generate(6, { // upperCaseAlphabets: false, // specialChars: false, // lowerCaseAlphabets: false, // digits: true, // }); // // Create user with the generated OTP // const user = await User.create({ // ...request, // otp, // role: Boolean(UserCount) ? request.role || 'user' : 'super admin', // }); // // Generate JWT token // const token = jwt.sign( // { // _id: user._id, // // email: user.email, // }, // process.env.JWT_SECRET, // { // expiresIn: '7d', // } // ); // // Path to the HTML file // const htmlFilePath = path.join( // process.cwd(), // 'src/email-templates', // 'otp.html' // ); // // Read HTML file content // let htmlContent = fs.readFileSync(htmlFilePath, 'utf8'); // // Replace the placeholder with the OTP and user email // htmlContent = htmlContent.replace(/