feat: add featured doctors and health packages APIs
This commit is contained in:
@@ -34,6 +34,7 @@ export const getAllDoctors = async (req, res) => {
|
||||
workingStatus: doc.workingStatus,
|
||||
qualification: doc.qualification,
|
||||
isActive: doc.isActive,
|
||||
isFeatured: doc.isFeatured,
|
||||
experience: doc.experience,
|
||||
professionalSummary: doc.professionalSummary,
|
||||
globalSortOrder: doc.globalSortOrder,
|
||||
@@ -129,6 +130,7 @@ export const getDoctorByDoctorId = async (req, res) => {
|
||||
experience: doctor.experience,
|
||||
professionalSummary: doctor.professionalSummary,
|
||||
isActive: doctor.isActive,
|
||||
isFeatured: doctor.isFeatured,
|
||||
seo: {
|
||||
seoTitle: doctor.seo?.seoTitle ?? '',
|
||||
metaDescription: doctor.seo?.metaDescription ?? '',
|
||||
@@ -240,6 +242,7 @@ export const createDoctor = async (req, res) => {
|
||||
workingStatus,
|
||||
qualification,
|
||||
isActive,
|
||||
isFeatured,
|
||||
globalSortOrder,
|
||||
departments,
|
||||
experience,
|
||||
@@ -297,6 +300,7 @@ export const createDoctor = async (req, res) => {
|
||||
professionalSummary,
|
||||
seoId: seo.id,
|
||||
isActive: isActive !== undefined ? isActive : true,
|
||||
isFeatured: isFeatured !== undefined ? isFeatured : false,
|
||||
globalSortOrder: globalSortOrder !== undefined ? Number(globalSortOrder) : 0,
|
||||
},
|
||||
});
|
||||
@@ -361,6 +365,7 @@ export const updateDoctor = async (req, res) => {
|
||||
workingStatus,
|
||||
qualification,
|
||||
isActive,
|
||||
isFeatured,
|
||||
globalSortOrder,
|
||||
departments,
|
||||
experience,
|
||||
@@ -397,6 +402,19 @@ export const updateDoctor = async (req, res) => {
|
||||
message: `Doctor has been ${doctor.isActive ? 'deactivated' : 'activated'} successfully`,
|
||||
});
|
||||
}
|
||||
if (action === 'toggleFeatured') {
|
||||
await prisma.doctor.update({
|
||||
where: { id: doctor.id },
|
||||
data: {
|
||||
isFeatured: !doctor.isFeatured,
|
||||
},
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `Doctor has been ${doctor.isFeatured ? 'removed from featured' : 'marked as featured'} successfully`,
|
||||
});
|
||||
}
|
||||
|
||||
const messages = [];
|
||||
if (!doctorId) messages.push('Doctor ID is required');
|
||||
@@ -423,7 +441,8 @@ export const updateDoctor = async (req, res) => {
|
||||
image,
|
||||
workingStatus,
|
||||
qualification,
|
||||
isActive,
|
||||
isActive: isActive !== undefined ? isActive : undefined,
|
||||
isFeatured: isFeatured !== undefined ? isFeatured : undefined,
|
||||
experience: experience ? Number(experience) : null,
|
||||
professionalSummary,
|
||||
globalSortOrder: globalSortOrder !== undefined ? Number(globalSortOrder) : undefined,
|
||||
@@ -700,3 +719,52 @@ export const getDoctorTimingById = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getFeaturedDoctors = async (req, res) => {
|
||||
try {
|
||||
const doctors = await prisma.doctor.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
isFeatured: true,
|
||||
},
|
||||
include: {
|
||||
seo: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
departments: {
|
||||
include: {
|
||||
department: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [{ globalSortOrder: 'asc' }, { name: 'asc' }],
|
||||
});
|
||||
|
||||
const data = doctors.map((doc) => ({
|
||||
doctorId: doc.doctorId,
|
||||
name: doc.name,
|
||||
image: doc.image ?? '',
|
||||
designation: doc.designation,
|
||||
qualification: doc.qualification,
|
||||
experience: doc.experience,
|
||||
slug: doc.seo?.slug ?? '',
|
||||
departments: doc.departments.map((d) => ({
|
||||
departmentId: d.department.departmentId,
|
||||
departmentName: d.department.name,
|
||||
})),
|
||||
}));
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Failed to fetch featured doctors',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -486,3 +486,33 @@ export const getAllInquiries = async (req, res) => {
|
||||
return res.status(500).json({ success: false, message: 'Failed to fetch inquiries' });
|
||||
}
|
||||
};
|
||||
|
||||
export const getFeaturedPackages = async (req, res) => {
|
||||
try {
|
||||
const packages = await prisma.healthPackage.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
isFeatured: true,
|
||||
category: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
category: true,
|
||||
seo: true,
|
||||
},
|
||||
orderBy: [{ sortOrder: 'asc' }, { createdAt: 'desc' }],
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
data: packages,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: 'Failed to fetch featured packages',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user