feat:add email send functionality
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user