fix: doctor toggle logic

This commit is contained in:
Kailasdevdas
2026-05-13 14:19:42 +05:30
parent 199797fdf4
commit 988fbd28f1
3 changed files with 47 additions and 34 deletions
+6 -1
View File
@@ -273,6 +273,11 @@ export const updateDoctor = async (req, res) => {
}, },
}); });
const hasTimingData = departments?.some(
(dep) => dep.timing && Object.keys(dep.timing).length > 0,
);
if (departments && Array.isArray(departments) && hasTimingData) {
const oldRelations = await prisma.doctorDepartment.findMany({ const oldRelations = await prisma.doctorDepartment.findMany({
where: {doctorId: doctor.id}, where: {doctorId: doctor.id},
}); });
@@ -304,12 +309,12 @@ export const updateDoctor = async (req, res) => {
if (dep.timing) { if (dep.timing) {
const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} = const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} =
dep.timing; dep.timing;
await prisma.doctorTiming.create({ await prisma.doctorTiming.create({
data: {doctorDepartmentId: newDD.id, ...cleanTiming}, data: {doctorDepartmentId: newDD.id, ...cleanTiming},
}); });
} }
} }
}
res res
.status(200) .status(200)
+3 -1
View File
@@ -8,8 +8,10 @@ export interface Doctor {
designation?: string; designation?: string;
workingStatus?: string; workingStatus?: string;
qualification?: string; qualification?: string;
isActive: boolean;
globalSortOrder: number;
departments: { departments?: {
departmentId: string; departmentId: string;
timing?: { timing?: {
monday?: string; monday?: string;
+8 -2
View File
@@ -158,8 +158,14 @@ export default function DoctorPage() {
const handleToggleStatus = async (doc: any) => { const handleToggleStatus = async (doc: any) => {
try { try {
const updatedDoc = { ...doc, isActive: !doc.isActive }; const newStatus = !doc.isActive;
await updateDoctorApi(doc.doctorId, updatedDoc);
const payload = {
isActive: newStatus,
};
await updateDoctorApi(doc.doctorId, payload);
fetchAll(); fetchAll();
} catch (err) { } catch (err) {
console.error("Failed to update status", err); console.error("Failed to update status", err);