fix: doctor toggle logic #27
@@ -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({
|
||||
where: {doctorId: doctor.id},
|
||||
});
|
||||
@@ -304,12 +309,12 @@ export const updateDoctor = async (req, res) => {
|
||||
if (dep.timing) {
|
||||
const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} =
|
||||
dep.timing;
|
||||
|
||||
await prisma.doctorTiming.create({
|
||||
data: {doctorDepartmentId: newDD.id, ...cleanTiming},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res
|
||||
.status(200)
|
||||
|
||||
@@ -8,8 +8,10 @@ export interface Doctor {
|
||||
designation?: string;
|
||||
workingStatus?: string;
|
||||
qualification?: string;
|
||||
isActive: boolean;
|
||||
globalSortOrder: number;
|
||||
|
||||
departments: {
|
||||
departments?: {
|
||||
departmentId: string;
|
||||
timing?: {
|
||||
monday?: string;
|
||||
|
||||
@@ -158,8 +158,14 @@ export default function DoctorPage() {
|
||||
|
||||
const handleToggleStatus = async (doc: any) => {
|
||||
try {
|
||||
const updatedDoc = { ...doc, isActive: !doc.isActive };
|
||||
await updateDoctorApi(doc.doctorId, updatedDoc);
|
||||
const newStatus = !doc.isActive;
|
||||
|
||||
const payload = {
|
||||
isActive: newStatus,
|
||||
};
|
||||
|
||||
await updateDoctorApi(doc.doctorId, payload);
|
||||
|
||||
fetchAll();
|
||||
} catch (err) {
|
||||
console.error("Failed to update status", err);
|
||||
|
||||
Reference in New Issue
Block a user