// get specific appointments of user
router.get("/user/:userId", async (req, res) => {
try {
console.log("user_id", req.params.userId);
const user = await User.findById(req.params.userId);
console.log("user", user);
const uservalue = user._id;
console.log("user_value", uservalue);
const appointment = await Appointment.find({
user_id: uservalue
});
console.log("appointments", appointment);
const doctorNameValue = [];
appointment.forEach(async element => {
const doctor = element.doctor_id;
const doctorDetails = await Doctor.findById({
_id: doctor
});
doctorNameValue.push(doctorDetails);
console.log(doctorNameValue);
});
res.json({
appointments: appointment,
doctorNameValue
});
} catch (err) {
res.status(401).json({
message: err
});
}
});