[1.0.4] #29
@@ -273,42 +273,47 @@ export const updateDoctor = async (req, res) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const oldRelations = await prisma.doctorDepartment.findMany({
|
const hasTimingData = departments?.some(
|
||||||
where: {doctorId: doctor.id},
|
(dep) => dep.timing && Object.keys(dep.timing).length > 0,
|
||||||
});
|
);
|
||||||
|
|
||||||
for (const rel of oldRelations) {
|
if (departments && Array.isArray(departments) && hasTimingData) {
|
||||||
await prisma.doctorTiming.deleteMany({
|
const oldRelations = await prisma.doctorDepartment.findMany({
|
||||||
where: {doctorDepartmentId: rel.id},
|
where: {doctorId: doctor.id},
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await prisma.doctorDepartment.deleteMany({
|
|
||||||
where: {doctorId: doctor.id},
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const dep of departments) {
|
|
||||||
const targetDept = await prisma.department.findUnique({
|
|
||||||
where: {departmentId: dep.departmentId},
|
|
||||||
});
|
|
||||||
if (!targetDept) continue;
|
|
||||||
|
|
||||||
const newDD = await prisma.doctorDepartment.create({
|
|
||||||
data: {
|
|
||||||
doctorId: doctor.id,
|
|
||||||
departmentId: targetDept.id,
|
|
||||||
sortOrder: dep.sortOrder !== undefined ? Number(dep.sortOrder) : 0,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dep.timing) {
|
for (const rel of oldRelations) {
|
||||||
const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} =
|
await prisma.doctorTiming.deleteMany({
|
||||||
dep.timing;
|
where: {doctorDepartmentId: rel.id},
|
||||||
|
|
||||||
await prisma.doctorTiming.create({
|
|
||||||
data: {doctorDepartmentId: newDD.id, ...cleanTiming},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await prisma.doctorDepartment.deleteMany({
|
||||||
|
where: {doctorId: doctor.id},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const dep of departments) {
|
||||||
|
const targetDept = await prisma.department.findUnique({
|
||||||
|
where: {departmentId: dep.departmentId},
|
||||||
|
});
|
||||||
|
if (!targetDept) continue;
|
||||||
|
|
||||||
|
const newDD = await prisma.doctorDepartment.create({
|
||||||
|
data: {
|
||||||
|
doctorId: doctor.id,
|
||||||
|
departmentId: targetDept.id,
|
||||||
|
sortOrder: dep.sortOrder !== undefined ? Number(dep.sortOrder) : 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (dep.timing) {
|
||||||
|
const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} =
|
||||||
|
dep.timing;
|
||||||
|
await prisma.doctorTiming.create({
|
||||||
|
data: {doctorDepartmentId: newDD.id, ...cleanTiming},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user