diff --git a/resources/RetailDistributor/RetailDistributorController.js b/resources/RetailDistributor/RetailDistributorController.js index eecebea..06c2b28 100644 --- a/resources/RetailDistributor/RetailDistributorController.js +++ b/resources/RetailDistributor/RetailDistributorController.js @@ -1,6 +1,10 @@ import mongoose from "mongoose"; import RetailDistributor from "./RetailDistributorModel.js"; import validator from "validator"; +import password from "secure-random-password"; +import crypto from "crypto"; + +import sendEmail, { sendOtp } from "../../Utils/sendEmail.js"; export const loginRD = async (req, res) => { const { email, password } = req.body; @@ -87,7 +91,7 @@ export const ChangePasswordRD = async (req, res) => { } }; -export const forgotPassword = async (req, res) => { +export const forgotPasswordRD = async (req, res) => { try { // Check if email is provided const { email } = req.body; @@ -137,15 +141,10 @@ export const forgotPassword = async (req, res) => { } }; -export const UpdateProfile = async (req, res) => { - const { name, email } = req.body; +export const UpdateProfileRD = async (req, res) => { + const { name, mobile_number } = req.body; // Only expecting name from the request body - const userId = req.user._id; // Use the ID from params or authenticated user - - // Validate email if provided - if (email && !validator.isEmail(email)) { - return res.status(400).json({ message: "Invalid email address" }); - } + const userId = req.user._id; // User ID from authenticated user try { // Find the RetailDistributor by user ID @@ -156,27 +155,15 @@ export const UpdateProfile = async (req, res) => { } // Assuming you have an 'isVerified' field in your RetailDistributor schema - if (!retailDistributor.isVerified) { - return res - .status(400) - .json({ message: "Retail Distributor not verified" }); - } - - // Check if email is being changed and if it's already in use - if (email && email !== retailDistributor.email) { - const emailExists = await RetailDistributor.findOne({ email }); - if (emailExists && emailExists._id.toString() !== userId) { - return res.status(400).json({ - message: - "This Email ID is already in use by another Retail Distributor", - }); - } - retailDistributor.email = email; - } // Update name if provided if (name) { retailDistributor.name = name; + retailDistributor.mobile_number = mobile_number + ? mobile_number + : retailDistributor.mobile_number; + } else { + return res.status(400).json({ message: "Name is required" }); } // Save the updated RetailDistributor @@ -193,7 +180,7 @@ export const UpdateProfile = async (req, res) => { } }; -export const getmyProfile = async (req, res) => { +export const getmyProfileRD = async (req, res) => { try { // Fetch the profile data using the authenticated user's ID const myData = await RetailDistributor.findById(req.user?._id); diff --git a/resources/user/userController.js b/resources/user/userController.js index 011fa39..d719e01 100644 --- a/resources/user/userController.js +++ b/resources/user/userController.js @@ -14,7 +14,7 @@ import fs from "fs"; import path from "path"; import validator from "validator"; import ShippingAddress from "../ShippingAddresses/ShippingAddressModel.js"; -import {generatePassword} from "../../Utils/generatepassword.js"; +import { generatePassword } from "../../Utils/generatepassword.js"; // const generatePassword = (name, email) => { // // Combine name and email, and convert to lowercase // const combinedStr = (name + email).toLowerCase(); @@ -851,7 +851,7 @@ export const resetPassword = catchAsyncErrors(async (req, res, next) => { //6.Get User Detail export const getUserDetails = catchAsyncErrors(async (req, res, next) => { - const user = await User.findById(req.user.id); + const user = await User.findById(req.user?._id); res.status(200).json({ success: true,