2026-03-16 12:39:41 +05:30
|
|
|
import prisma from "../prisma/client.js";
|
2026-03-25 12:48:01 +05:30
|
|
|
import { sendEmail } from "../utils/sendEmail.js";
|
|
|
|
|
import { getEmailsByType } from "../utils/getEmailByTypes.js";
|
2026-03-16 12:39:41 +05:30
|
|
|
|
|
|
|
|
// CREATE ACADEMICS & RESEARCH
|
|
|
|
|
|
|
|
|
|
export const createAcademicsResearch = async (req, res) => {
|
|
|
|
|
try {
|
2026-03-25 12:48:01 +05:30
|
|
|
const { fullName, number, emailId, subject, courseName, message } =
|
|
|
|
|
req.body;
|
2026-03-16 12:39:41 +05:30
|
|
|
|
|
|
|
|
if (!fullName || !number) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
success: false,
|
|
|
|
|
message: "Full name and number are required",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await prisma.academicsResearch.create({
|
|
|
|
|
data: {
|
|
|
|
|
fullName,
|
|
|
|
|
number,
|
|
|
|
|
emailId,
|
|
|
|
|
subject,
|
|
|
|
|
courseName,
|
|
|
|
|
message,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-25 12:48:01 +05:30
|
|
|
try {
|
|
|
|
|
const emailList = await getEmailsByType("ACADEMICS");
|
|
|
|
|
|
|
|
|
|
if (emailList && emailList.length > 0) {
|
|
|
|
|
await sendEmail({
|
|
|
|
|
to: emailList,
|
|
|
|
|
subject: "New Academics & Research Inquiry",
|
|
|
|
|
html: `
|
2026-04-27 17:29:33 +05:30
|
|
|
<div style="font-family: Arial, sans-serif; background-color: #f4f6f8; padding: 20px;">
|
|
|
|
|
|
|
|
|
|
<div style="max-width: 600px; margin: auto; background: #ffffff; border-radius: 10px; overflow: hidden; box-shadow: 0 4px 10px rgba(0,0,0,0.05);">
|
|
|
|
|
|
|
|
|
|
<!-- Header -->
|
|
|
|
|
<div style="background-color: #0d6efd; color: #ffffff; padding: 20px;">
|
|
|
|
|
<h2 style="margin: 0;">GG Hospital</h2>
|
|
|
|
|
<p style="margin: 5px 0 0; font-size: 14px;">
|
|
|
|
|
New Academics & Research Inquiry
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-03-25 12:48:01 +05:30
|
|
|
|
2026-04-27 17:29:33 +05:30
|
|
|
<!-- Body -->
|
|
|
|
|
<div style="padding: 20px; color: #333;">
|
|
|
|
|
|
|
|
|
|
<h3 style="margin-top: 0;">Contact Details</h3>
|
|
|
|
|
|
|
|
|
|
<table style="width: 100%; border-collapse: collapse;">
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="padding: 8px 0;"><b>Name:</b></td>
|
|
|
|
|
<td style="padding: 8px 0;">${fullName}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="padding: 8px 0;"><b>Phone:</b></td>
|
|
|
|
|
<td style="padding: 8px 0;">${number}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="padding: 8px 0;"><b>Email:</b></td>
|
|
|
|
|
<td style="padding: 8px 0;">${emailId || "-"}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="padding: 8px 0;"><b>Course:</b></td>
|
|
|
|
|
<td style="padding: 8px 0;">${courseName || "-"}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="padding: 8px 0;"><b>Subject:</b></td>
|
|
|
|
|
<td style="padding: 8px 0;">${subject || "-"}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
2026-03-25 12:48:01 +05:30
|
|
|
|
2026-04-27 17:29:33 +05:30
|
|
|
<!-- Message Box -->
|
|
|
|
|
<div style="margin-top: 20px;">
|
|
|
|
|
<h3>Message</h3>
|
|
|
|
|
<div style="
|
|
|
|
|
background: #f8f9fa;
|
|
|
|
|
padding: 15px;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
line-height: 1.6;
|
|
|
|
|
white-space: pre-wrap;
|
|
|
|
|
word-break: break-word;
|
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
|
">
|
|
|
|
|
${message ? message.replace(/\n/g, "<br/>") : "-"}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-25 12:48:01 +05:30
|
|
|
|
2026-04-27 17:29:33 +05:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Footer -->
|
|
|
|
|
<div style="background: #f1f1f1; padding: 15px; text-align: center; font-size: 12px; color: #666;">
|
|
|
|
|
This message was sent from the GG Hospital website (Academics & Research Inquiry).
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
`,
|
2026-03-25 12:48:01 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Academics email failed:", err);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 12:39:41 +05:30
|
|
|
res.status(200).json({
|
|
|
|
|
success: true,
|
|
|
|
|
status: 200,
|
|
|
|
|
data,
|
|
|
|
|
message: "Academics & Research added successfully",
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
res.status(500).json({
|
|
|
|
|
success: false,
|
|
|
|
|
message: "Failed to add Academics & Research inquiry",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// GET ALL
|
|
|
|
|
|
|
|
|
|
export const getAcademicsResearch = async (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await prisma.academicsResearch.findMany({
|
|
|
|
|
orderBy: {
|
|
|
|
|
createdAt: "desc",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
success: true,
|
|
|
|
|
data,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
res.status(500).json({
|
|
|
|
|
success: false,
|
|
|
|
|
message: "Failed to fetch records",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// GET SINGLE
|
|
|
|
|
|
|
|
|
|
export const getSingleAcademicsResearch = async (req, res) => {
|
|
|
|
|
try {
|
2026-03-25 12:48:01 +05:30
|
|
|
const { id } = req.params;
|
2026-03-16 12:39:41 +05:30
|
|
|
|
|
|
|
|
const data = await prisma.academicsResearch.findUnique({
|
|
|
|
|
where: {
|
|
|
|
|
id: Number(id),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
success: false,
|
|
|
|
|
message: "Record not found",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
success: true,
|
|
|
|
|
data,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
res.status(500).json({
|
|
|
|
|
success: false,
|
|
|
|
|
message: "Failed to fetch record",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// DELETE
|
|
|
|
|
|
|
|
|
|
export const deleteAcademicsResearch = async (req, res) => {
|
|
|
|
|
try {
|
2026-03-25 12:48:01 +05:30
|
|
|
const { id } = req.params;
|
2026-03-16 12:39:41 +05:30
|
|
|
|
|
|
|
|
await prisma.academicsResearch.delete({
|
|
|
|
|
where: {
|
|
|
|
|
id: Number(id),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
success: true,
|
|
|
|
|
message: "Record deleted successfully",
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
res.status(500).json({
|
|
|
|
|
success: false,
|
|
|
|
|
message: "Failed to delete record",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|