Skip to content

Commit

Permalink
Merge pull request #39 from ShubhaMahobia/38-changning-email-for-node…
Browse files Browse the repository at this point in the history
…mailer

Refactor prescriptionController.js to send prescription data via emai…
  • Loading branch information
ShubhaMahobia authored Apr 11, 2024
2 parents 5439037 + 2851c70 commit a0f78cc
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions controller/prescriptionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,34 @@ exports.generatePrecription = async (req, res) => {

// Find doctor details using doctorId
const doctor = await UserDoctor.findOne({
firebaseUserId: document.doctorId,
firebaseUserId: document.doctorId,
});

// Send prescription data via email
const transporter = nodemailer.createTransport({
// Configure your email provider here
service: "gmail",
auth: {
user: "archikirar@gmail.com", // Your email address
pass: "hmda upmd yorx xsnb", // Your email password or app password if using Gmail
user: "mahobiashubham4@gmail.com",
pass: "oczd hhhw kzms bpfa",
},
});

const mailOptions = {
from:doctor.Email ,
from: doctor.Email,
to: patient.Email, // Replace with the recipient's email address
subject: "New Prescription",
text: `A new prescription has been submitted:\nDoctor Name: ${doctor.firstName} ${doctor.firstName}\nDate: ${newPrescription.date}\nTitle: ${newPrescription.title}\nDescription: ${newPrescription.description}`,
attachments: [
{
filename: "prescription.pdf", // Change the filename as needed
path: newPrescription.documentLink, // Provide the file path
// Alternatively, you can provide attachment content as a Buffer
// content: Buffer.from('attachment content'),
// contentType: 'application/pdf' // Specify the content type if needed
filename: "prescription.pdf",
path: newPrescription.documentLink,
},
],
};

await transporter.sendMail(mailOptions);
await newPrescription.save(); //Saving command for saving apointments to database
await newPrescription.save();
return res.status(200).json({
success: true,
message: "Prescription Generated successfully",
Expand Down Expand Up @@ -105,13 +102,10 @@ exports.getPrescriptionDetails = async (req, res) => {
message: "prescription not found",
});
}

// Find patient details using patientId
const patient = await UserPatient.findOne({
firebaseUserId: prescription.patientId,
});

// Find doctor details using doctorId
const doctor = await UserDoctor.findOne({
firebaseUserId: prescription.doctorId,
});
Expand Down

0 comments on commit a0f78cc

Please sign in to comment.