chore: file formatting
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import prisma from "../prisma/client.js";
|
||||
import prisma from '../prisma/client.js';
|
||||
|
||||
// get doctors
|
||||
|
||||
export const getAllDoctors = async (req, res) => {
|
||||
try {
|
||||
const {admin} = req.query;
|
||||
const { admin } = req.query;
|
||||
|
||||
const doctors = await prisma.doctor.findMany({
|
||||
where: admin === "true" ? {} : {isActive: true},
|
||||
where: admin === 'true' ? {} : { isActive: true },
|
||||
include: {
|
||||
seo: true,
|
||||
departments: {
|
||||
@@ -18,18 +18,18 @@ export const getAllDoctors = async (req, res) => {
|
||||
},
|
||||
specializations: {
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
createdAt: 'asc',
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [{globalSortOrder: "asc"}, {name: "asc"}],
|
||||
orderBy: [{ globalSortOrder: 'asc' }, { name: 'asc' }],
|
||||
});
|
||||
|
||||
const formatted = doctors.map((doc, index) => ({
|
||||
SL_NO: String(index + 1),
|
||||
doctorId: doc.doctorId,
|
||||
name: doc.name,
|
||||
image: doc.image ?? "",
|
||||
image: doc.image ?? '',
|
||||
designation: doc.designation,
|
||||
workingStatus: doc.workingStatus,
|
||||
qualification: doc.qualification,
|
||||
@@ -43,15 +43,15 @@ export const getAllDoctors = async (req, res) => {
|
||||
description: item.description,
|
||||
})),
|
||||
seo: {
|
||||
seoTitle: doc.seo?.seoTitle ?? "",
|
||||
metaDescription: doc.seo?.metaDescription ?? "",
|
||||
focusKeyphrase: doc.seo?.focusKeyphrase ?? "",
|
||||
slug: doc.seo?.slug ?? "",
|
||||
seoTitle: doc.seo?.seoTitle ?? '',
|
||||
metaDescription: doc.seo?.metaDescription ?? '',
|
||||
focusKeyphrase: doc.seo?.focusKeyphrase ?? '',
|
||||
slug: doc.seo?.slug ?? '',
|
||||
tags: doc.seo?.tags ?? [],
|
||||
|
||||
ogTitle: doc.seo?.ogTitle ?? "",
|
||||
ogDescription: doc.seo?.ogDescription ?? "",
|
||||
ogImage: doc.seo?.ogImage ?? "",
|
||||
ogTitle: doc.seo?.ogTitle ?? '',
|
||||
ogDescription: doc.seo?.ogDescription ?? '',
|
||||
ogImage: doc.seo?.ogImage ?? '',
|
||||
},
|
||||
departments: doc.departments.map((d) => {
|
||||
const t = d.timing || {};
|
||||
@@ -69,7 +69,7 @@ export const getAllDoctors = async (req, res) => {
|
||||
return {
|
||||
departmentId: d.department.departmentId,
|
||||
departmentName: d.department.name,
|
||||
timing: timingArray.join(" & "),
|
||||
timing: timingArray.join(' & '),
|
||||
deptSortOrder: d.sortOrder,
|
||||
};
|
||||
}),
|
||||
@@ -83,7 +83,7 @@ export const getAllDoctors = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch doctors",
|
||||
message: 'Failed to fetch doctors',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -92,10 +92,10 @@ export const getAllDoctors = async (req, res) => {
|
||||
|
||||
export const getDoctorByDoctorId = async (req, res) => {
|
||||
try {
|
||||
const {doctorId} = req.params;
|
||||
const { doctorId } = req.params;
|
||||
|
||||
const doctor = await prisma.doctor.findUnique({
|
||||
where: {doctorId},
|
||||
where: { doctorId },
|
||||
include: {
|
||||
seo: true,
|
||||
specializations: true,
|
||||
@@ -111,28 +111,28 @@ export const getDoctorByDoctorId = async (req, res) => {
|
||||
if (!doctor) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Doctor not found",
|
||||
message: 'Doctor not found',
|
||||
});
|
||||
}
|
||||
|
||||
const response = {
|
||||
doctorId: doctor.doctorId,
|
||||
name: doctor.name,
|
||||
image: doctor.image ?? "",
|
||||
image: doctor.image ?? '',
|
||||
designation: doctor.designation,
|
||||
workingStatus: doctor.workingStatus,
|
||||
qualification: doctor.qualification,
|
||||
experience: doctor.experience,
|
||||
professionalSummary: doctor.professionalSummary,
|
||||
seo: {
|
||||
seoTitle: doctor.seo?.seoTitle ?? "",
|
||||
metaDescription: doctor.seo?.metaDescription ?? "",
|
||||
focusKeyphrase: doctor.seo?.focusKeyphrase ?? "",
|
||||
slug: doctor.seo?.slug ?? "",
|
||||
seoTitle: doctor.seo?.seoTitle ?? '',
|
||||
metaDescription: doctor.seo?.metaDescription ?? '',
|
||||
focusKeyphrase: doctor.seo?.focusKeyphrase ?? '',
|
||||
slug: doctor.seo?.slug ?? '',
|
||||
tags: doctor.seo?.tags ?? [],
|
||||
ogTitle: doctor.seo?.ogTitle ?? "",
|
||||
ogDescription: doctor.seo?.ogDescription ?? "",
|
||||
ogImage: doctor.seo?.ogImage ?? "",
|
||||
ogTitle: doctor.seo?.ogTitle ?? '',
|
||||
ogDescription: doctor.seo?.ogDescription ?? '',
|
||||
ogImage: doctor.seo?.ogImage ?? '',
|
||||
},
|
||||
specializations:
|
||||
doctor.specializations?.map((item) => ({
|
||||
@@ -155,7 +155,7 @@ export const getDoctorByDoctorId = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch doctor",
|
||||
message: 'Failed to fetch doctor',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -163,30 +163,30 @@ export const getDoctorByDoctorId = async (req, res) => {
|
||||
// get doctors by department
|
||||
export const getDoctorsByDepartmentId = async (req, res) => {
|
||||
try {
|
||||
const {Department_ID} = req.query;
|
||||
const { Department_ID } = req.query;
|
||||
|
||||
if (!Department_ID) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Department_ID is required",
|
||||
message: 'Department_ID is required',
|
||||
});
|
||||
}
|
||||
|
||||
const department = await prisma.department.findUnique({
|
||||
where: {departmentId: Department_ID},
|
||||
where: { departmentId: Department_ID },
|
||||
});
|
||||
|
||||
if (!department) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Department not found",
|
||||
message: 'Department not found',
|
||||
});
|
||||
}
|
||||
|
||||
const doctorsInDept = await prisma.doctorDepartment.findMany({
|
||||
where: {
|
||||
departmentId: department.id,
|
||||
doctor: {isActive: true},
|
||||
doctor: { isActive: true },
|
||||
},
|
||||
include: {
|
||||
doctor: {
|
||||
@@ -199,16 +199,16 @@ export const getDoctorsByDepartmentId = async (req, res) => {
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {sortOrder: "asc"},
|
||||
orderBy: { sortOrder: 'asc' },
|
||||
});
|
||||
|
||||
const result = doctorsInDept.map((d) => ({
|
||||
GG_ID: d.doctor.doctorId,
|
||||
Name: d.doctor.name,
|
||||
image: d.doctor.image ?? "",
|
||||
image: d.doctor.image ?? '',
|
||||
designation: d.doctor.designation,
|
||||
hierarchyOrder: d.sortOrder,
|
||||
slug: d.doctor.seo?.slug ?? "",
|
||||
slug: d.doctor.seo?.slug ?? '',
|
||||
}));
|
||||
|
||||
res.status(200).json({
|
||||
@@ -219,7 +219,7 @@ export const getDoctorsByDepartmentId = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch doctors",
|
||||
message: 'Failed to fetch doctors',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -251,18 +251,18 @@ export const createDoctor = async (req, res) => {
|
||||
} = req.body;
|
||||
const messages = [];
|
||||
|
||||
if (!doctorId) messages.push("Doctor ID is required");
|
||||
if (!name?.trim()) messages.push("Doctor name is required");
|
||||
if (!designation?.trim()) messages.push("Designation is required");
|
||||
if (!qualification?.trim()) messages.push("Qualification is required");
|
||||
if (!doctorId) messages.push('Doctor ID is required');
|
||||
if (!name?.trim()) messages.push('Doctor name is required');
|
||||
if (!designation?.trim()) messages.push('Designation is required');
|
||||
if (!qualification?.trim()) messages.push('Qualification is required');
|
||||
if (!departments || departments.length === 0) {
|
||||
messages.push("At least one department is required");
|
||||
messages.push('At least one department is required');
|
||||
}
|
||||
|
||||
if (messages.length > 0) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: messages.join(", "),
|
||||
message: messages.join(', '),
|
||||
});
|
||||
}
|
||||
const seo = await prisma.seo.create({
|
||||
@@ -292,14 +292,13 @@ export const createDoctor = async (req, res) => {
|
||||
professionalSummary,
|
||||
seoId: seo.id,
|
||||
isActive: isActive !== undefined ? isActive : true,
|
||||
globalSortOrder:
|
||||
globalSortOrder !== undefined ? Number(globalSortOrder) : 0,
|
||||
globalSortOrder: globalSortOrder !== undefined ? Number(globalSortOrder) : 0,
|
||||
},
|
||||
});
|
||||
|
||||
for (const dep of departments) {
|
||||
const department = await prisma.department.findUnique({
|
||||
where: {departmentId: dep.departmentId},
|
||||
where: { departmentId: dep.departmentId },
|
||||
});
|
||||
|
||||
if (!department) continue;
|
||||
@@ -335,13 +334,13 @@ export const createDoctor = async (req, res) => {
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
message: "Doctor created successfully",
|
||||
message: 'Doctor created successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to create doctor",
|
||||
message: 'Failed to create doctor',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -349,7 +348,7 @@ export const createDoctor = async (req, res) => {
|
||||
//update doctors
|
||||
export const updateDoctor = async (req, res) => {
|
||||
try {
|
||||
const {doctorId, action} = req.params;
|
||||
const { doctorId, action } = req.params;
|
||||
const {
|
||||
name,
|
||||
designation,
|
||||
@@ -375,17 +374,14 @@ export const updateDoctor = async (req, res) => {
|
||||
if (!doctorId) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Doctor ID is required",
|
||||
message: 'Doctor ID is required',
|
||||
});
|
||||
}
|
||||
const doctor = await prisma.doctor.findUnique({where: {doctorId}});
|
||||
if (!doctor)
|
||||
return res
|
||||
.status(404)
|
||||
.json({success: false, message: "Doctor not found"});
|
||||
if (action === "toggleStatus") {
|
||||
const doctor = await prisma.doctor.findUnique({ where: { doctorId } });
|
||||
if (!doctor) return res.status(404).json({ success: false, message: 'Doctor not found' });
|
||||
if (action === 'toggleStatus') {
|
||||
await prisma.doctor.update({
|
||||
where: {id: doctor.id},
|
||||
where: { id: doctor.id },
|
||||
data: {
|
||||
isActive: !doctor.isActive,
|
||||
},
|
||||
@@ -393,31 +389,29 @@ export const updateDoctor = async (req, res) => {
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `Doctor has been ${
|
||||
doctor.isActive ? "deactivated" : "activated"
|
||||
} successfully`,
|
||||
message: `Doctor has been ${doctor.isActive ? 'deactivated' : 'activated'} successfully`,
|
||||
});
|
||||
}
|
||||
|
||||
const messages = [];
|
||||
if (!doctorId) messages.push("Doctor ID is required");
|
||||
if (!name?.trim()) messages.push("Doctor name is required");
|
||||
if (!qualification?.trim()) messages.push("Qualification is required");
|
||||
if (!designation?.trim()) messages.push("Designation is required");
|
||||
if (!doctorId) messages.push('Doctor ID is required');
|
||||
if (!name?.trim()) messages.push('Doctor name is required');
|
||||
if (!qualification?.trim()) messages.push('Qualification is required');
|
||||
if (!designation?.trim()) messages.push('Designation is required');
|
||||
|
||||
if (!departments || departments.length === 0) {
|
||||
messages.push("At least one department is required");
|
||||
messages.push('At least one department is required');
|
||||
}
|
||||
|
||||
if (messages.length > 0) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: messages.join(", "),
|
||||
message: messages.join(', '),
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.doctor.update({
|
||||
where: {id: doctor.id},
|
||||
where: { id: doctor.id },
|
||||
data: {
|
||||
name,
|
||||
designation,
|
||||
@@ -427,8 +421,7 @@ export const updateDoctor = async (req, res) => {
|
||||
isActive,
|
||||
experience: experience ? Number(experience) : null,
|
||||
professionalSummary,
|
||||
globalSortOrder:
|
||||
globalSortOrder !== undefined ? Number(globalSortOrder) : undefined,
|
||||
globalSortOrder: globalSortOrder !== undefined ? Number(globalSortOrder) : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -520,8 +513,7 @@ export const updateDoctor = async (req, res) => {
|
||||
});
|
||||
|
||||
if (dep.timing && Object.keys(dep.timing).length > 0) {
|
||||
const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} =
|
||||
dep.timing;
|
||||
const { id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming } = dep.timing;
|
||||
|
||||
await prisma.doctorTiming.create({
|
||||
data: {
|
||||
@@ -554,58 +546,56 @@ export const updateDoctor = async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
res
|
||||
.status(200)
|
||||
.json({success: true, message: "Doctor updated successfully"});
|
||||
res.status(200).json({ success: true, message: 'Doctor updated successfully' });
|
||||
} catch (error) {
|
||||
console.error("Update Error:", error);
|
||||
res.status(500).json({success: false, message: "Failed to update doctor"});
|
||||
console.error('Update Error:', error);
|
||||
res.status(500).json({ success: false, message: 'Failed to update doctor' });
|
||||
}
|
||||
};
|
||||
//delete doctor
|
||||
|
||||
export const deleteDoctor = async (req, res) => {
|
||||
try {
|
||||
const {doctorId} = req.params;
|
||||
const { doctorId } = req.params;
|
||||
|
||||
const doctor = await prisma.doctor.findUnique({
|
||||
where: {doctorId},
|
||||
where: { doctorId },
|
||||
});
|
||||
|
||||
if (!doctor) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Doctor not found",
|
||||
message: 'Doctor not found',
|
||||
});
|
||||
}
|
||||
|
||||
const doctorDepartments = await prisma.doctorDepartment.findMany({
|
||||
where: {doctorId: doctor.id},
|
||||
where: { doctorId: doctor.id },
|
||||
});
|
||||
|
||||
for (const dd of doctorDepartments) {
|
||||
await prisma.doctorTiming.deleteMany({
|
||||
where: {doctorDepartmentId: dd.id},
|
||||
where: { doctorDepartmentId: dd.id },
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.doctorDepartment.deleteMany({
|
||||
where: {doctorId: doctor.id},
|
||||
where: { doctorId: doctor.id },
|
||||
});
|
||||
|
||||
await prisma.doctor.delete({
|
||||
where: {id: doctor.id},
|
||||
where: { id: doctor.id },
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Doctor deleted successfully",
|
||||
message: 'Doctor deleted successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to delete doctor",
|
||||
message: 'Failed to delete doctor',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -630,14 +620,14 @@ export const getDoctorTimings = async (req, res) => {
|
||||
return {
|
||||
Doctor_ID: doc.doctorId,
|
||||
Doctor: doc.name,
|
||||
Monday: timing.monday || "",
|
||||
Tuesday: timing.tuesday || "",
|
||||
Wednesday: timing.wednesday || "",
|
||||
Thursday: timing.thursday || "",
|
||||
Friday: timing.friday || "",
|
||||
Saturday: timing.saturday || "",
|
||||
Sunday: timing.sunday || "",
|
||||
Additional: timing.additional || "",
|
||||
Monday: timing.monday || '',
|
||||
Tuesday: timing.tuesday || '',
|
||||
Wednesday: timing.wednesday || '',
|
||||
Thursday: timing.thursday || '',
|
||||
Friday: timing.friday || '',
|
||||
Saturday: timing.saturday || '',
|
||||
Sunday: timing.sunday || '',
|
||||
Additional: timing.additional || '',
|
||||
};
|
||||
});
|
||||
|
||||
@@ -649,7 +639,7 @@ export const getDoctorTimings = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch doctor timings",
|
||||
message: 'Failed to fetch doctor timings',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -657,10 +647,10 @@ export const getDoctorTimings = async (req, res) => {
|
||||
|
||||
export const getDoctorTimingById = async (req, res) => {
|
||||
try {
|
||||
const {doctorId} = req.params;
|
||||
const { doctorId } = req.params;
|
||||
|
||||
const doctor = await prisma.doctor.findUnique({
|
||||
where: {doctorId},
|
||||
where: { doctorId },
|
||||
include: {
|
||||
departments: {
|
||||
include: {
|
||||
@@ -674,7 +664,7 @@ export const getDoctorTimingById = async (req, res) => {
|
||||
if (!doctor) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Doctor not found",
|
||||
message: 'Doctor not found',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -697,7 +687,7 @@ export const getDoctorTimingById = async (req, res) => {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch doctor timing",
|
||||
message: 'Failed to fetch doctor timing',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user