Fixed the bugs
This commit is contained in:
parent
9c31ccdd7c
commit
457ebcadb9
@ -1,23 +1,18 @@
|
||||
import express from "express";
|
||||
import {
|
||||
ChangePasswordRD,
|
||||
forgotPassword,
|
||||
getmyProfile,
|
||||
forgotPasswordRD,
|
||||
getmyProfileRD,
|
||||
loginRD,
|
||||
UpdateProfile,
|
||||
UpdateProfileRD,
|
||||
} from "./RetailDistributorController.js";
|
||||
import { isAuthenticatedRD } from "../../middlewares/rdAuth.js";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/rd-login").post(loginRD);
|
||||
router.route("/rd-get-me").get(isAuthenticatedRD, getmyProfile);
|
||||
router.post("/forgot-password", forgotPassword);
|
||||
router.route("/rd-get-me").get(isAuthenticatedRD, getmyProfileRD);
|
||||
router.post("/forgot-password", forgotPasswordRD);
|
||||
router.put("/rd-password/update", isAuthenticatedRD, ChangePasswordRD);
|
||||
router.patch(
|
||||
"/rd-profile/update",
|
||||
isAuthenticatedRD,
|
||||
|
||||
UpdateProfile
|
||||
);
|
||||
router.patch("/rd-profile/update", isAuthenticatedRD, UpdateProfileRD);
|
||||
export default router;
|
||||
|
@ -2,7 +2,7 @@ import RetailDistributor from "./RetailDistributorModel.js";
|
||||
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) => {
|
||||
const { email, password } = req.body;
|
||||
@ -90,7 +90,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;
|
||||
@ -140,8 +140,8 @@ export const forgotPassword = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const UpdateProfile = async (req, res) => {
|
||||
const { name } = req.body; // Only expecting name from the request 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; // User ID from authenticated user
|
||||
|
||||
@ -158,6 +158,9 @@ export const UpdateProfile = async (req, res) => {
|
||||
// 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" });
|
||||
}
|
||||
@ -176,7 +179,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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user