register remaining part
This commit is contained in:
parent
f49468d00e
commit
0a55f0824f
@ -38,20 +38,29 @@ export default sendEmail;
|
||||
// const messagebirdClient = messagebird(apiKey);
|
||||
import { initClient } from "messagebird";
|
||||
const messagebird = initClient("e7HGr3kMl6su4c79DKjNAwlLQ");
|
||||
export const sendOtp = (recipient, message) => {
|
||||
// e7HGr3kMl6su4c79DKjNAwlLQ
|
||||
//7oOgyzfNuwBnqMc2oK6aGfczs
|
||||
//11yKY8EbdFJpugJzaKyAH3YaK
|
||||
|
||||
|
||||
export const sendOtp = async (recipient, message) => {
|
||||
if (!recipient || !message) {
|
||||
return;
|
||||
}
|
||||
const params = {
|
||||
originator: "TestMessage",
|
||||
recipients: `+918874747774`,
|
||||
body: "hi how are you",
|
||||
originator: "tavisa",
|
||||
recipients: [recipient],
|
||||
body: message,
|
||||
};
|
||||
|
||||
|
||||
messagebird.messages.create(params, (err, response) => {
|
||||
if (err) {
|
||||
console.error("Error sending message:", err);
|
||||
console.error("Error sending message-------:", err);
|
||||
return;
|
||||
}
|
||||
console.log("Message sent successfully:", response);
|
||||
console.log("Message rrrrrrrrrrrrrrrr:", response?.recipients?.items);
|
||||
// console.log("Message sent successfully:", response);
|
||||
// console.log("Message details:", response, response?.recipients?.items);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -2,32 +2,36 @@
|
||||
|
||||
import crypto from 'crypto';
|
||||
import Patient from './PatientModel.js'
|
||||
import { sendOtp } from '../../Utils/sendEmail.js';
|
||||
export const register = async (req, res) => {
|
||||
const { name, mobileNumber } = req.body;
|
||||
let { name, countryCode, mobileNumber } = req.body;
|
||||
// Trim the country code and mobile number
|
||||
countryCode = countryCode.trim();
|
||||
mobileNumber = mobileNumber.trim();
|
||||
const fullMobileNumber = `${countryCode}${mobileNumber}`;
|
||||
try {
|
||||
let patient = await Patient.findOne({ mobileNumber });
|
||||
|
||||
let patient = await Patient.findOne({ mobileNumber: fullMobileNumber });
|
||||
if (patient && patient.isVerified) {
|
||||
return res.status(400).json({ message: 'Patient already registered and verified for This Mobile No.' });
|
||||
}
|
||||
|
||||
const otp = crypto.randomInt(100000, 1000000).toString();
|
||||
|
||||
// const otp ="123456";
|
||||
|
||||
const otpExpires = Date.now() + 10 * 60 * 1000; // 10 minutes
|
||||
const otpExpires = Date.now() + 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
if (patient) {
|
||||
patient.otp = otp;
|
||||
patient.otpExpires = otpExpires;
|
||||
} else {
|
||||
patient = new Patient({ name, mobileNumber, otp, otpExpires });
|
||||
patient = new Patient({ name, mobileNumber: fullMobileNumber, otp, otpExpires });
|
||||
}
|
||||
|
||||
await patient.save();
|
||||
// await sendOtp(mobileNumber, otp);
|
||||
await sendOtp(fullMobileNumber, `Your Verification OTP is: ${otp}`);
|
||||
res.cookie('patientId', patient._id.toString(),
|
||||
{ httpOnly: true }
|
||||
); // 1 day in milliseconds
|
||||
// { httpOnly: true, maxAge: 24 * 60 * 60 * 1000 }
|
||||
|
||||
res.status(200).json({patient, message: `OTP ${otp} sent to your mobile number successfully` });
|
||||
|
||||
return res.status(200).json({ patient, message: `OTP ${otp} sent to your mobile number ${fullMobileNumber} successfully` });
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: error.message ? error.message : "Server error!",
|
||||
@ -38,6 +42,7 @@ export const register = async (req, res) => {
|
||||
export const verifyOtp = async (req, res) => {
|
||||
const { mobileNumber, otp } = req.body;
|
||||
try {
|
||||
mobileNumber = mobileNumber.trim();
|
||||
const patient = await Patient.findOne({ mobileNumber });
|
||||
|
||||
if (!patient) {
|
||||
@ -58,9 +63,210 @@ export const verifyOtp = async (req, res) => {
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: error.message ? error.message : "Server error!",
|
||||
}); }
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//get All Product
|
||||
export const getAllPatient = async (req, res) => {
|
||||
try {
|
||||
const PAGE_SIZE = parseInt(req.query?.show || "10");
|
||||
const page = parseInt(req.query?.page - 1 || "0");
|
||||
let obj = {};
|
||||
if (req.query?.name)
|
||||
obj.name = {
|
||||
$regex: new RegExp(req.query.name),
|
||||
$options: "i",
|
||||
};
|
||||
if (req.query?.category) obj.category = req.query.category;
|
||||
if (req.query?.isVerified)
|
||||
obj.isVerified = req.query.isVerified;
|
||||
const total = await Patient.countDocuments(obj);
|
||||
const patient = await Patient.find(obj)
|
||||
// .populate({
|
||||
// path: "category addedBy master_GST variants.gst_Id",
|
||||
// select: "name categoryName tax",
|
||||
// })
|
||||
.limit(PAGE_SIZE)
|
||||
.skip(PAGE_SIZE * page)
|
||||
// .sort("name")
|
||||
.sort({
|
||||
createdAt: -1,
|
||||
})
|
||||
.exec();
|
||||
|
||||
if (patient) {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
total_data: total,
|
||||
total_pages: Math.ceil(total / PAGE_SIZE),
|
||||
patient,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: error.message ? error.message : "Something went wrong!",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const create1RegistrationDetails = async (req, res) => {
|
||||
const {
|
||||
email,
|
||||
password,
|
||||
confirmPassword,
|
||||
} = req.body;
|
||||
const patientId = req.cookies.patientId;
|
||||
if (!patientId) {
|
||||
return res.status(400).json({ message: 'Patient did not registered Or verified' });
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
return res.status(400).json({ message: 'Password and confirm password do not match' });
|
||||
}
|
||||
try {
|
||||
const patient = await Patient.findById(patientId);
|
||||
if (!patient || !patient.isVerified) {
|
||||
return res.status(400).json({ message: 'Patient not found or not verified' });
|
||||
}
|
||||
|
||||
// Check if another patient with the same email exists
|
||||
const emailExists = await Patient.findOne({ email });
|
||||
if (emailExists && emailExists._id.toString() !== patientId) {
|
||||
return res.status(400).json({ message: 'Email is already in use By Another patient' });
|
||||
}
|
||||
patient.email = email;
|
||||
patient.password = password;
|
||||
|
||||
await patient.save();
|
||||
|
||||
res.status(200).json({ patient, message: 'Registration details updated successfully' });
|
||||
} catch (error) {
|
||||
|
||||
res.status(500).json({
|
||||
message: error.message ? error.message : "Server error!",
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const EnterPatientDetails = async (req, res) => {
|
||||
const {
|
||||
gender,
|
||||
weightValue,
|
||||
weightUnit,
|
||||
heightValue,
|
||||
heightUnit,
|
||||
age,
|
||||
} = req.body;
|
||||
|
||||
switch (true) {
|
||||
case !gender:
|
||||
return res.status(400).json({ message: 'Gender is required' });
|
||||
case !weightValue:
|
||||
return res.status(400).json({ message: 'weight Value is required' });
|
||||
case !weightUnit:
|
||||
return res.status(400).json({ message: 'weight Unit is required' });
|
||||
case !heightValue:
|
||||
return res.status(400).json({ message: 'height Value is required' });
|
||||
case !heightUnit:
|
||||
return res.status(400).json({ message: 'height Unit is required' });
|
||||
case !age:
|
||||
return res.status(400).json({ message: 'Age is required and Must Be a Number' });
|
||||
default:
|
||||
|
||||
//gender Validate
|
||||
if (!['Male', 'Female'].includes(gender)) {
|
||||
return res.status(400).json({ message: 'Invalid gender:gender Must be "Male" or "Female"' });
|
||||
}
|
||||
// Validate weightUnit
|
||||
if (!['Kgs', 'Lbs'].includes(weightUnit)) {
|
||||
return res.status(400).json({ message: 'Invalid weight unit. Must be "Kgs" or "Lbs"' });
|
||||
}
|
||||
// Ensure weightValue is a number
|
||||
if (isNaN(weightValue)) {
|
||||
return res.status(400).json({ message: 'Weight value must be a number' });
|
||||
}
|
||||
// Validate heightUnit
|
||||
if (!['Ft', 'Cm'].includes(heightUnit)) {
|
||||
return res.status(400).json({ message: 'Invalid height unit. Must be "Ft" or "Cm"' });
|
||||
}
|
||||
// Ensure heightValue is a number
|
||||
if (isNaN(heightValue)) {
|
||||
return res.status(400).json({ message: 'Height value must be a number' });
|
||||
}
|
||||
if (isNaN(age)) {
|
||||
return res.status(400).json({ message: 'age must be a number' });
|
||||
}
|
||||
const patientId = req.cookies.patientId;
|
||||
if (!patientId) {
|
||||
return res.status(400).json({ message: 'Patient did not registered Or verified' });
|
||||
}
|
||||
try {
|
||||
const patient = await Patient.findById(patientId);
|
||||
if (!patient || !patient.isVerified) {
|
||||
return res.status(400).json({ message: 'Patient not found or not verified' });
|
||||
}
|
||||
patient.gender = gender;
|
||||
patient.weight = {
|
||||
value: weightValue,
|
||||
unit: weightUnit,
|
||||
};
|
||||
patient.height = {
|
||||
value: heightValue,
|
||||
unit: heightUnit,
|
||||
};
|
||||
patient.age = age;
|
||||
await patient.save();
|
||||
res.status(200).json({ patient, message: 'Patient details updated successfully' });
|
||||
} catch (error) {
|
||||
|
||||
res.status(500).json({
|
||||
message: error.message ? error.message : "Server error!",
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const EnterPersonalDetails = async (req, res) => {
|
||||
const {
|
||||
commonHealthComplaints,
|
||||
familyHistory,
|
||||
personalHistory,
|
||||
dailyRoutine,
|
||||
} = req.body;
|
||||
const patientId = req.cookies.patientId;
|
||||
if (!patientId) {
|
||||
return res.status(400).json({ message: 'Patient did not registered Or verified' });
|
||||
}
|
||||
try {
|
||||
const patient = await Patient.findById(patientId);
|
||||
if (!patient || !patient.isVerified) {
|
||||
return res.status(400).json({ message: 'Patient not found or not verified' });
|
||||
}
|
||||
|
||||
// Check if another patient with the same email exists
|
||||
|
||||
patient.commonHealthComplaints = commonHealthComplaints;
|
||||
patient.familyHistory = familyHistory;
|
||||
patient.personalHistory = personalHistory;
|
||||
patient.dailyRoutine = dailyRoutine;
|
||||
await patient.save();
|
||||
res.status(200).json({ patient, message: 'Patient Pesonal details updated successfully' });
|
||||
} catch (error) {
|
||||
|
||||
res.status(500).json({
|
||||
message: error.message ? error.message : "Server error!",
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export const completeRegistration = async (req, res) => {
|
||||
const {
|
||||
mobileNumber,
|
||||
@ -110,3 +316,37 @@ res.status(500).json({
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const Otp = async (req, res) => {
|
||||
// const { name, mobileNumber } = req.body;
|
||||
try {
|
||||
// let patient = await Patient.findOne({ mobileNumber });
|
||||
|
||||
// if (patient && patient.isVerified) {
|
||||
// return res.status(400).json({ message: 'Patient already registered and verified for This Mobile No.' });
|
||||
// }
|
||||
|
||||
// const otp = crypto.randomInt(100000, 1000000).toString();
|
||||
|
||||
// // const otp ="123456";
|
||||
|
||||
// const otpExpires = Date.now() + 10 * 60 * 1000; // 10 minutes
|
||||
|
||||
// if (patient) {
|
||||
// patient.otp = otp;
|
||||
// patient.otpExpires = otpExpires;
|
||||
// } else {
|
||||
// patient = new Patient({ name, mobileNumber, otp, otpExpires });
|
||||
// }
|
||||
|
||||
// await patient.save();
|
||||
await sendOtp();
|
||||
|
||||
// res.status(200).json({patient, message: `OTP ${otp} sent to your mobile number successfully` });
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: error.message ? error.message : "Server error!",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -31,7 +31,13 @@ const patientSchema = new mongoose.Schema(
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
email: String,
|
||||
email: {
|
||||
type: String,
|
||||
required: false,
|
||||
unique: true,
|
||||
validate: [validator.isEmail, "Please Enter a valid Email"],
|
||||
},
|
||||
|
||||
password: {
|
||||
type: String,
|
||||
minLength: [6, "Password should be greater than 6 characters"],
|
||||
@ -51,14 +57,26 @@ const patientSchema = new mongoose.Schema(
|
||||
type: String,
|
||||
enum: ['Male', 'Female'],
|
||||
},
|
||||
|
||||
weight: {
|
||||
value: {
|
||||
type: Number,
|
||||
},
|
||||
unit: {
|
||||
type: String,
|
||||
enum: ['Kilos', 'Lbs'],
|
||||
enum: ['Kgs', 'Lbs'],
|
||||
},
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
enum: ['Feet', 'Cms'],
|
||||
value: {
|
||||
type: Number,
|
||||
},
|
||||
unit: {
|
||||
type: String,
|
||||
enum: ['Ft', 'Cm'],
|
||||
},
|
||||
},
|
||||
|
||||
age: Number,
|
||||
commonHealthComplaints: String,
|
||||
familyHistory: String,
|
||||
|
@ -2,11 +2,19 @@ import express from "express";
|
||||
|
||||
const router = express.Router();
|
||||
// import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
import { completeRegistration, register, verifyOtp } from "./PatientController.js";
|
||||
import { EnterPatientDetails, EnterPersonalDetails, Otp, completeRegistration, create1RegistrationDetails, getAllPatient, register, verifyOtp } from "./PatientController.js";
|
||||
|
||||
|
||||
router.post('/register', register);
|
||||
router.post('/verify-otp', verifyOtp);
|
||||
router.post('/rgstr_details-p1', create1RegistrationDetails);
|
||||
router.post('/rgstr_details-p2', EnterPatientDetails);
|
||||
router.post('/rgstr_psrnl_details-p3', EnterPersonalDetails);
|
||||
|
||||
router.get('/getAll', getAllPatient);
|
||||
|
||||
router.post('/complete-registration', completeRegistration);
|
||||
router.get('/otp', Otp);
|
||||
|
||||
|
||||
export default router;
|
||||
|
@ -26,7 +26,7 @@ export const registerUser = async (req, res) => {
|
||||
const myCloud = await cloudinary.uploader.upload(
|
||||
files.tempFilePath,
|
||||
{
|
||||
folder: "ATP/user-image",
|
||||
folder: "tavisa/user-image",
|
||||
},
|
||||
function (error, result) {
|
||||
result, error;
|
||||
@ -66,8 +66,7 @@ export const registerUser = async (req, res) => {
|
||||
Welcome to AyurPulse - Let the Shopping Begin!
|
||||
</p>
|
||||
<br/>
|
||||
<p style="color: #555; font-size: 15px;">You can login into :${
|
||||
role === "Employee" || role === "admin"
|
||||
<p style="color: #555; font-size: 15px;">You can login into :${role === "Employee" || role === "admin"
|
||||
? `https://admin.smellika.com/`
|
||||
: `https://smellika.com`
|
||||
} </p>
|
||||
@ -338,7 +337,7 @@ export const updateProfile = catchAsyncErrors(async (req, res, next) => {
|
||||
|
||||
// const myCloud = await cloudinary.v2.uploader.upload(userImage.tempFilePath,
|
||||
// {
|
||||
// folder: "ATP/user-image",
|
||||
// folder: "tavisa/user-image",
|
||||
|
||||
// });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user