Fixed the bugs
This commit is contained in:
parent
9c31ccdd7c
commit
457ebcadb9
@ -1,23 +1,18 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import {
|
import {
|
||||||
ChangePasswordRD,
|
ChangePasswordRD,
|
||||||
forgotPassword,
|
forgotPasswordRD,
|
||||||
getmyProfile,
|
getmyProfileRD,
|
||||||
loginRD,
|
loginRD,
|
||||||
UpdateProfile,
|
UpdateProfileRD,
|
||||||
} from "./RetailDistributorController.js";
|
} from "./RetailDistributorController.js";
|
||||||
import { isAuthenticatedRD } from "../../middlewares/rdAuth.js";
|
import { isAuthenticatedRD } from "../../middlewares/rdAuth.js";
|
||||||
|
|
||||||
const router = express.Router();
|
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, getmyProfileRD);
|
||||||
router.post("/forgot-password", forgotPassword);
|
router.post("/forgot-password", forgotPasswordRD);
|
||||||
router.put("/rd-password/update", isAuthenticatedRD, ChangePasswordRD);
|
router.put("/rd-password/update", isAuthenticatedRD, ChangePasswordRD);
|
||||||
router.patch(
|
router.patch("/rd-profile/update", isAuthenticatedRD, UpdateProfileRD);
|
||||||
"/rd-profile/update",
|
|
||||||
isAuthenticatedRD,
|
|
||||||
|
|
||||||
UpdateProfile
|
|
||||||
);
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -2,7 +2,7 @@ import RetailDistributor from "./RetailDistributorModel.js";
|
|||||||
import validator from "validator";
|
import validator from "validator";
|
||||||
import password from "secure-random-password";
|
import password from "secure-random-password";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import catchAsyncErrors from "../../middlewares/catchAsyncErrors.js";
|
|
||||||
import sendEmail, { sendOtp } from "../../Utils/sendEmail.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;
|
||||||
@ -90,7 +90,7 @@ export const ChangePasswordRD = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const forgotPassword = async (req, res) => {
|
export const forgotPasswordRD = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// Check if email is provided
|
// Check if email is provided
|
||||||
const { email } = req.body;
|
const { email } = req.body;
|
||||||
@ -140,8 +140,8 @@ export const forgotPassword = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UpdateProfile = async (req, res) => {
|
export const UpdateProfileRD = async (req, res) => {
|
||||||
const { name } = req.body; // Only expecting name from the request body
|
const { name, mobile_number } = req.body; // Only expecting name from the request body
|
||||||
|
|
||||||
const userId = req.user._id; // User ID from authenticated user
|
const userId = req.user._id; // User ID from authenticated user
|
||||||
|
|
||||||
@ -158,6 +158,9 @@ export const UpdateProfile = async (req, res) => {
|
|||||||
// Update name if provided
|
// Update name if provided
|
||||||
if (name) {
|
if (name) {
|
||||||
retailDistributor.name = name;
|
retailDistributor.name = name;
|
||||||
|
retailDistributor.mobile_number = mobile_number
|
||||||
|
? mobile_number
|
||||||
|
: retailDistributor.mobile_number;
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({ message: "Name is required" });
|
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 {
|
try {
|
||||||
// Fetch the profile data using the authenticated user's ID
|
// Fetch the profile data using the authenticated user's ID
|
||||||
const myData = await RetailDistributor.findById(req.user?._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
|
//6.Get User Detail
|
||||||
export const getUserDetails = catchAsyncErrors(async (req, res, next) => {
|
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({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user