Compare commits
No commits in common. "9c31ccdd7c247e124b449c0f13c74bdc6bc3dfff" and "b76d9b3c6d8a5f3c3d67cc2c2b25ce19d7c10651" have entirely different histories.
9c31ccdd7c
...
b76d9b3c6d
@ -13,7 +13,12 @@ const router = express.Router();
|
|||||||
router.route("/rd-login").post(loginRD);
|
router.route("/rd-login").post(loginRD);
|
||||||
router.route("/rd-get-me").get(isAuthenticatedRD, getmyProfile);
|
router.route("/rd-get-me").get(isAuthenticatedRD, getmyProfile);
|
||||||
router.post("/forgot-password", forgotPassword);
|
router.post("/forgot-password", forgotPassword);
|
||||||
router.put("/rd-password/update", isAuthenticatedRD, ChangePasswordRD);
|
router.put(
|
||||||
|
"/rd-password/update",
|
||||||
|
isAuthenticatedRD,
|
||||||
|
|
||||||
|
ChangePasswordRD
|
||||||
|
);
|
||||||
router.patch(
|
router.patch(
|
||||||
"/rd-profile/update",
|
"/rd-profile/update",
|
||||||
isAuthenticatedRD,
|
isAuthenticatedRD,
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import RetailDistributor from "./RetailDistributorModel.js";
|
import RetailDistributor from "./RetailDistributorModel.js";
|
||||||
import validator from "validator";
|
import validator from "validator";
|
||||||
import password from "secure-random-password";
|
|
||||||
import crypto from "crypto";
|
|
||||||
import catchAsyncErrors from "../../middlewares/catchAsyncErrors.js";
|
|
||||||
import sendEmail, { sendOtp } from "../../Utils/sendEmail.js";
|
|
||||||
export const loginRD = async (req, res) => {
|
export const loginRD = async (req, res) => {
|
||||||
const { email, password } = req.body;
|
const { email, password } = req.body;
|
||||||
|
|
||||||
@ -141,9 +137,14 @@ export const forgotPassword = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const UpdateProfile = async (req, res) => {
|
export const UpdateProfile = async (req, res) => {
|
||||||
const { name } = req.body; // Only expecting name from the request body
|
const { name, email } = req.body;
|
||||||
|
|
||||||
const userId = req.user._id; // User ID from authenticated user
|
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" });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Find the RetailDistributor by user ID
|
// Find the RetailDistributor by user ID
|
||||||
@ -154,12 +155,27 @@ export const UpdateProfile = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assuming you have an 'isVerified' field in your RetailDistributor schema
|
// 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
|
// Update name if provided
|
||||||
if (name) {
|
if (name) {
|
||||||
retailDistributor.name = name;
|
retailDistributor.name = name;
|
||||||
} else {
|
|
||||||
return res.status(400).json({ message: "Name is required" });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the updated RetailDistributor
|
// Save the updated RetailDistributor
|
||||||
|
Loading…
Reference in New Issue
Block a user