feat:add email send functionality

This commit is contained in:
ARJUN S THAMPI
2026-03-19 13:12:04 +05:30
parent 1bbf7f9c1c
commit 834eaad3c3
17 changed files with 759 additions and 6 deletions
@@ -1,5 +1,6 @@
import prisma from "../prisma/client.js";
//CREATE APPOINTMENT
import {sendEmail} from "../utils/sendEmail.js";
import {getEmailsByType} from "../utils/getEmailByTypes.js";
export const createAppointment = async (req, res) => {
try {
@@ -29,6 +30,29 @@ export const createAppointment = async (req, res) => {
},
});
try {
const emailList = await getEmailsByType("APPOINTMENT");
if (emailList) {
await sendEmail({
to: emailList,
subject: "New Appointment Booked",
html: `
<h2>New Appointment Booked</h2>
<p><b>Name:</b> ${name}</p>
<p><b>Phone:</b> ${mobileNumber}</p>
<p><b>Email:</b> ${email || "-"}</p>
<p><b>Doctor:</b> ${appointment.doctor?.name}</p>
<p><b>Department:</b> ${appointment.department?.name}</p>
<p><b>Date:</b> ${new Date(date).toLocaleDateString()}</p>
<p><b>Message:</b> ${message || "-"}</p>
`,
});
}
} catch (err) {
console.error("Email failed:", err);
}
res.status(201).json({
success: true,
message: "Appointment booked successfully",