chore: file formatting
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import prisma from "../prisma/client.js";
|
||||
import { sendEmail } from "../utils/sendEmail.js";
|
||||
import { getEmailsByType } from "../utils/getEmailByTypes.js";
|
||||
import prisma from '../prisma/client.js';
|
||||
import { sendEmail } from '../utils/sendEmail.js';
|
||||
import { getEmailsByType } from '../utils/getEmailByTypes.js';
|
||||
|
||||
export const createAppointment = async (req, res) => {
|
||||
try {
|
||||
const { name, mobileNumber, email, message, date, doctorId, departmentId } =
|
||||
req.body;
|
||||
const { name, mobileNumber, email, message, date, doctorId, departmentId } = req.body;
|
||||
|
||||
if (!name || !mobileNumber || !doctorId || !departmentId || !date) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Required fields missing",
|
||||
message: 'Required fields missing',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,12 +30,12 @@ export const createAppointment = async (req, res) => {
|
||||
});
|
||||
|
||||
try {
|
||||
const emailList = await getEmailsByType("APPOINTMENT");
|
||||
const emailList = await getEmailsByType('APPOINTMENT');
|
||||
|
||||
if (emailList) {
|
||||
await sendEmail({
|
||||
to: emailList,
|
||||
subject: "New Appointment Booked",
|
||||
subject: 'New Appointment Booked',
|
||||
html: `
|
||||
<div style="font-family: Arial, sans-serif; background-color: #f4f6f8; padding: 20px;">
|
||||
|
||||
@@ -66,7 +65,7 @@ export const createAppointment = async (req, res) => {
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0;"><b>Email:</b></td>
|
||||
<td style="padding: 8px 0;">${email || "-"}</td>
|
||||
<td style="padding: 8px 0;">${email || '-'}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -75,19 +74,19 @@ export const createAppointment = async (req, res) => {
|
||||
<table style="width: 100%; border-collapse: collapse;">
|
||||
<tr>
|
||||
<td style="padding: 8px 0;"><b>Doctor:</b></td>
|
||||
<td style="padding: 8px 0;">${appointment.doctor?.name || "-"}</td>
|
||||
<td style="padding: 8px 0;">${appointment.doctor?.name || '-'}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0;"><b>Department:</b></td>
|
||||
<td style="padding: 8px 0;">${appointment.department?.name || "-"}</td>
|
||||
<td style="padding: 8px 0;">${appointment.department?.name || '-'}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0;"><b>Date:</b></td>
|
||||
<td style="padding: 8px 0;">
|
||||
${new Date(date).toLocaleDateString("en-GB", {
|
||||
day: "2-digit",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
${new Date(date).toLocaleDateString('en-GB', {
|
||||
day: '2-digit',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
})}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -105,7 +104,7 @@ export const createAppointment = async (req, res) => {
|
||||
word-break: break-word;
|
||||
overflow-wrap: anywhere;
|
||||
">
|
||||
${message ? message.replace(/\n/g, "<br/>") : "-"}
|
||||
${message ? message.replace(/\n/g, '<br/>') : '-'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -123,19 +122,19 @@ export const createAppointment = async (req, res) => {
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Email failed:", err);
|
||||
console.error('Email failed:', err);
|
||||
}
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
message: "Appointment booked successfully",
|
||||
message: 'Appointment booked successfully',
|
||||
data: appointment,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to create appointment",
|
||||
message: 'Failed to create appointment',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -152,11 +151,9 @@ export const getAppointments = async (req, res) => {
|
||||
|
||||
const where = {};
|
||||
|
||||
const hasSingleDate = date && date.trim() !== "";
|
||||
const hasSingleDate = date && date.trim() !== '';
|
||||
|
||||
const hasRange =
|
||||
(startDate && startDate.trim() !== "") ||
|
||||
(endDate && endDate.trim() !== "");
|
||||
const hasRange = (startDate && startDate.trim() !== '') || (endDate && endDate.trim() !== '');
|
||||
|
||||
if (hasSingleDate) {
|
||||
const start = new Date(date);
|
||||
@@ -174,14 +171,14 @@ export const getAppointments = async (req, res) => {
|
||||
if (!hasSingleDate && hasRange) {
|
||||
const dateFilter = {};
|
||||
|
||||
if (startDate && startDate.trim() !== "") {
|
||||
if (startDate && startDate.trim() !== '') {
|
||||
const start = new Date(startDate);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
|
||||
dateFilter.gte = start;
|
||||
}
|
||||
|
||||
if (endDate && endDate.trim() !== "") {
|
||||
if (endDate && endDate.trim() !== '') {
|
||||
const end = new Date(endDate);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
|
||||
@@ -191,11 +188,11 @@ export const getAppointments = async (req, res) => {
|
||||
where.date = dateFilter;
|
||||
}
|
||||
|
||||
if (search && search.trim() !== "") {
|
||||
if (search && search.trim() !== '') {
|
||||
where.OR = [
|
||||
{ name: { contains: search, mode: "insensitive" } },
|
||||
{ name: { contains: search, mode: 'insensitive' } },
|
||||
{ mobileNumber: { contains: search } },
|
||||
{ email: { contains: search, mode: "insensitive" } },
|
||||
{ email: { contains: search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -207,7 +204,7 @@ export const getAppointments = async (req, res) => {
|
||||
department: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
createdAt: 'desc',
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
@@ -233,7 +230,7 @@ export const getAppointments = async (req, res) => {
|
||||
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch appointments",
|
||||
message: 'Failed to fetch appointments',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -257,7 +254,7 @@ export const getAppointment = async (req, res) => {
|
||||
if (!appointment) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Appointment not found",
|
||||
message: 'Appointment not found',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -269,7 +266,7 @@ export const getAppointment = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch appointment",
|
||||
message: 'Failed to fetch appointment',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -289,7 +286,7 @@ export const getAppointmentsByDoctor = async (req, res) => {
|
||||
department: true,
|
||||
},
|
||||
orderBy: {
|
||||
date: "asc",
|
||||
date: 'asc',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -301,7 +298,7 @@ export const getAppointmentsByDoctor = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch doctor appointments",
|
||||
message: 'Failed to fetch doctor appointments',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -330,7 +327,7 @@ export const getAppointmentsByDepartment = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch department appointments",
|
||||
message: 'Failed to fetch department appointments',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -354,14 +351,14 @@ export const updateAppointment = async (req, res) => {
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Appointment updated successfully",
|
||||
message: 'Appointment updated successfully',
|
||||
data: appointment,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to update appointment",
|
||||
message: 'Failed to update appointment',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -380,13 +377,13 @@ export const deleteAppointment = async (req, res) => {
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Appointment deleted successfully",
|
||||
message: 'Appointment deleted successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to delete appointment",
|
||||
message: 'Failed to delete appointment',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user