change mobile number Update Profile get Profile etc
This commit is contained in:
parent
edb977c601
commit
a9e4b349aa
@ -48,4 +48,3 @@ export const isAuthenticatedPatient = async (req, res, next) => {
|
|||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ export const create1RegistrationDetails = async (req, res) => {
|
|||||||
|
|
||||||
// Check if another patient with the same email exists
|
// Check if another patient with the same email exists
|
||||||
const emailExists = await Patient.findOne({ email });
|
const emailExists = await Patient.findOne({ email });
|
||||||
if (emailExists && emailExists._id.toString() !== req.patient._id) {
|
if (emailExists && emailExists._id.toString() !== req.patient._id.toString()) {
|
||||||
return res.status(400).json({ message: 'This Email ID is already in use By Another patient' });
|
return res.status(400).json({ message: 'This Email ID is already in use By Another patient' });
|
||||||
}
|
}
|
||||||
patient.email = email;
|
patient.email = email;
|
||||||
@ -575,7 +575,7 @@ export const UpdateProile = async (req, res) => {
|
|||||||
dailyRoutine,
|
dailyRoutine,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
// Validate email
|
// Validate email
|
||||||
if (email && !validator.isEmail(email)) {
|
if (!validator.isEmail(email)) {
|
||||||
return res.status(400).json({ message: 'Invalid email address' });
|
return res.status(400).json({ message: 'Invalid email address' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,7 +613,7 @@ export const UpdateProile = async (req, res) => {
|
|||||||
}
|
}
|
||||||
if (email) {
|
if (email) {
|
||||||
const emailExists = await Patient.findOne({ email });
|
const emailExists = await Patient.findOne({ email });
|
||||||
if (emailExists && emailExists._id.toString() !== req.patient._id) {
|
if (emailExists && emailExists._id.toString() !== req.patient._id.toString()) {
|
||||||
return res.status(400).json({ message: 'This Email ID is already in use By Another patient' });
|
return res.status(400).json({ message: 'This Email ID is already in use By Another patient' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -635,19 +635,7 @@ export const UpdateProile = async (req, res) => {
|
|||||||
,
|
,
|
||||||
{ new: true } // Return the updated document
|
{ new: true } // Return the updated document
|
||||||
);
|
);
|
||||||
// patient.gender = gender;
|
|
||||||
// patient.weight = {
|
|
||||||
// value: weightValue,
|
|
||||||
// unit: weightUnit,
|
|
||||||
// };
|
|
||||||
// patient.height = {
|
|
||||||
// value: heightValue,
|
|
||||||
// unit: heightUnit,
|
|
||||||
// };
|
|
||||||
// patient.age = age;
|
|
||||||
// await patient.save();
|
|
||||||
// const patientResponse = patient.toObject();
|
|
||||||
// delete patientResponse.password;
|
|
||||||
return res.status(200).json({ patient: NewPatientDetail, message: 'Profile updated successfully' });
|
return res.status(200).json({ patient: NewPatientDetail, message: 'Profile updated successfully' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
@ -656,6 +644,50 @@ export const UpdateProile = async (req, res) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//change Patient password
|
||||||
|
export const ChangePassword = async (req, res) => {
|
||||||
|
const { oldPassword, newPassword, confirmPassword } = req.body
|
||||||
|
|
||||||
|
if (!oldPassword) {
|
||||||
|
return res.status(400).json({ message: 'Please Enter Old password' });
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!newPassword) {
|
||||||
|
return res.status(400).json({ message: 'Please Enter New Password ' });
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!confirmPassword) {
|
||||||
|
return res.status(400).json({ message: 'Please Enter Confirm Password' });
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const patient = await Patient.findById(req.patient._id).select("+password");
|
||||||
|
|
||||||
|
const isPasswordMatched = await patient.comparePassword(req.body.oldPassword);
|
||||||
|
|
||||||
|
if (!isPasswordMatched) {
|
||||||
|
return res.status(400).json({ message: 'Old password is incorrect' });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.body.newPassword !== req.body.confirmPassword) {
|
||||||
|
return res.status(400).json({ message: 'old password and confirm Password does not match' });
|
||||||
|
|
||||||
|
}
|
||||||
|
patient.password = req.body.newPassword;
|
||||||
|
await patient.save();
|
||||||
|
// const token = patient.getJWTToken();
|
||||||
|
|
||||||
|
return res.status(200).json({ success: true, message: 'Password updated successfully' });
|
||||||
|
|
||||||
|
// sendToken(patient, 200, res);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: error.message ? error.message : "Server error!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
import { EnterPatientDetails, EnterPersonalDetails, Otp, UploadProfileImage, create1RegistrationDetails, deletePatient, forgotPassword, getAllPatient, loginPatient, register, updateMobileNumber, verifyUpdatedMobileOtp, verifyOtp, UpdateProile, getmyProfile } from "./PatientController.js";
|
import { EnterPatientDetails, EnterPersonalDetails, Otp, UploadProfileImage, create1RegistrationDetails, deletePatient, forgotPassword, getAllPatient, loginPatient, register, updateMobileNumber, verifyUpdatedMobileOtp, verifyOtp, UpdateProile, getmyProfile, ChangePassword } from "./PatientController.js";
|
||||||
import { isAuthenticatedPatient } from "../../middlewares/PatientAuth.js";
|
import { isAuthenticatedPatient } from "../../middlewares/PatientAuth.js";
|
||||||
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||||
|
|
||||||
@ -25,6 +25,9 @@ router.post('/forgot-password', forgotPassword);
|
|||||||
router.post('/profile-image/upload', isAuthenticatedPatient, UploadProfileImage);
|
router.post('/profile-image/upload', isAuthenticatedPatient, UploadProfileImage);
|
||||||
router.patch('/profile/update', isAuthenticatedPatient, UpdateProile);
|
router.patch('/profile/update', isAuthenticatedPatient, UpdateProile);
|
||||||
|
|
||||||
|
//change password
|
||||||
|
router.put('/password/update', isAuthenticatedPatient, ChangePassword);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//delete Patient
|
//delete Patient
|
||||||
|
Loading…
Reference in New Issue
Block a user