From 29d2ed6b96275e8abc5a13abe055f6d08f3e4c56 Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Wed, 8 Apr 2026 16:39:29 +0530 Subject: [PATCH 1/3] feat: get department by name --- .../src/controllers/department.controller.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/backend/src/controllers/department.controller.js b/backend/src/controllers/department.controller.js index 7b6debb..17c199b 100644 --- a/backend/src/controllers/department.controller.js +++ b/backend/src/controllers/department.controller.js @@ -29,6 +29,53 @@ export const getAllDepartments = async (req, res) => { } }; +export const getDepartmentByName = async (req, res) => { + try { + const {name} = req.query; + + if (!name) { + return res.status(400).json({ + success: false, + message: "Department name is required", + }); + } + + const department = await prisma.department.findFirst({ + where: { + name: name, + }, + }); + + if (!department) { + return res.status(404).json({ + success: false, + message: "Department not found", + }); + } + + const response = { + departmentId: department.departmentId, + name: department.name, + para1: department.para1 ?? "", + para2: department.para2 ?? "", + para3: department.para3 ?? "", + facilities: department.facilities ?? "", + services: department.services ?? "", + }; + + return res.status(200).json({ + success: true, + data: [response], + }); + } catch (error) { + console.error(error); + return res.status(500).json({ + success: false, + message: "Failed to fetch department", + }); + } +}; + export async function createDepartment(req, res) { try { const {departmentId, name, para1, para2, para3, facilities, services} = From 9c44c66b22e836a9ff4ef1408d1565ec3bdcaf15 Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Wed, 8 Apr 2026 16:40:42 +0530 Subject: [PATCH 2/3] feat: get doctors by department --- backend/src/controllers/doctor.controller.js | 194 ++++++++++--------- 1 file changed, 103 insertions(+), 91 deletions(-) diff --git a/backend/src/controllers/doctor.controller.js b/backend/src/controllers/doctor.controller.js index a7087a3..dde079f 100644 --- a/backend/src/controllers/doctor.controller.js +++ b/backend/src/controllers/doctor.controller.js @@ -16,38 +16,35 @@ export const getAllDoctors = async (req, res) => { orderBy: {name: "asc"}, }); - const formatted = doctors.map((doc, index) => { - return { - SL_NO: String(index + 1), - doctorId: doc.doctorId, - name: doc.name, - designation: doc.designation, - workingStatus: doc.workingStatus, - qualification: doc.qualification, + const formatted = doctors.map((doc, index) => ({ + SL_NO: String(index + 1), + doctorId: doc.doctorId, + name: doc.name, + designation: doc.designation, + workingStatus: doc.workingStatus, + qualification: doc.qualification, - departments: doc.departments.map((d) => { - const t = d.timing || {}; + departments: doc.departments.map((d) => { + const t = d.timing || {}; - const timingArray = [ - t.monday && `Monday ${t.monday}`, - t.tuesday && `Tuesday ${t.tuesday}`, - t.wednesday && `Wednesday ${t.wednesday}`, - t.thursday && `Thursday ${t.thursday}`, - t.friday && `Friday ${t.friday}`, - t.saturday && `Saturday ${t.saturday}`, - t.sunday && `Sunday ${t.sunday}`, - t.additional && t.additional, - ].filter(Boolean); + const timingArray = [ + t.monday && `Monday ${t.monday}`, + t.tuesday && `Tuesday ${t.tuesday}`, + t.wednesday && `Wednesday ${t.wednesday}`, + t.thursday && `Thursday ${t.thursday}`, + t.friday && `Friday ${t.friday}`, + t.saturday && `Saturday ${t.saturday}`, + t.sunday && `Sunday ${t.sunday}`, + t.additional && t.additional, + ].filter(Boolean); - return { - departmentId: d.department.departmentId, - departmentName: d.department.name, - - timing: timingArray.join(" & "), - }; - }), - }; - }); + return { + departmentId: d.department.departmentId, + departmentName: d.department.name, + timing: timingArray.join(" & "), + }; + }), + })); res.status(200).json({ success: true, @@ -113,6 +110,54 @@ export const getDoctorByDoctorId = async (req, res) => { } }; +// get doctors by department +export const getDoctorsByDepartmentId = async (req, res) => { + try { + const {Department_ID} = req.query; + + if (!Department_ID) { + return res.status(400).json({ + success: false, + message: "Department_ID is required", + }); + } + + const department = await prisma.department.findUnique({ + where: {departmentId: Department_ID}, + }); + + if (!department) { + return res.status(404).json({ + success: false, + message: "Department not found", + }); + } + + const doctors = await prisma.doctorDepartment.findMany({ + where: {departmentId: department.id}, + include: { + doctor: true, + }, + }); + + const result = doctors.map((d) => ({ + GG_ID: d.doctor.doctorId, + Name: d.doctor.name, + })); + + res.status(200).json({ + success: true, + data: result, + }); + } catch (error) { + console.error(error); + res.status(500).json({ + success: false, + message: "Failed to fetch doctors", + }); + } +}; + // add doctors export const createDoctor = async (req, res) => { try { @@ -184,20 +229,14 @@ export const updateDoctor = async (req, res) => { }); if (!doctor) { - return res.status(404).json({ - success: false, - message: "Doctor not found", - }); + return res + .status(404) + .json({success: false, message: "Doctor not found"}); } await prisma.doctor.update({ where: {id: doctor.id}, - data: { - name, - designation, - workingStatus, - qualification, - }, + data: {name, designation, workingStatus, qualification}, }); const oldRelations = await prisma.doctorDepartment.findMany({ @@ -229,25 +268,24 @@ export const updateDoctor = async (req, res) => { }); if (dep.timing) { + const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} = + dep.timing; + await prisma.doctorTiming.create({ data: { doctorDepartmentId: doctorDepartment.id, - ...dep.timing, + ...cleanTiming, }, }); } } - res.status(200).json({ - success: true, - message: "Doctor updated successfully", - }); + res + .status(200) + .json({success: true, message: "Doctor updated successfully"}); } catch (error) { - console.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 @@ -256,13 +294,6 @@ export const deleteDoctor = async (req, res) => { try { const {doctorId} = req.params; - if (!doctorId) { - return res.status(400).json({ - success: false, - message: "Doctor ID is required", - }); - } - const doctor = await prisma.doctor.findUnique({ where: {doctorId}, }); @@ -270,7 +301,7 @@ export const deleteDoctor = async (req, res) => { if (!doctor) { return res.status(404).json({ success: false, - message: `Doctor with ID ${doctorId} not found`, + message: "Doctor not found", }); } @@ -294,7 +325,7 @@ export const deleteDoctor = async (req, res) => { res.status(200).json({ success: true, - message: `Doctor ${doctorId} deleted successfully`, + message: "Doctor deleted successfully", }); } catch (error) { console.error(error); @@ -320,23 +351,19 @@ export const getDoctorTimings = async (req, res) => { }); const result = doctors.map((doc) => { - let timing = {}; - - if (doc.departments.length > 0) { - timing = doc.departments[0].timing ?? {}; - } + const timing = doc.departments[0]?.timing || {}; 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 || "", }; }); @@ -380,26 +407,11 @@ export const getDoctorTimingById = async (req, res) => { const result = { doctorId: doctor.doctorId, doctorName: doctor.name, - - departments: doctor.departments.map((d) => { - const t = d.timing || {}; - - return { - departmentId: d.department.departmentId, - departmentName: d.department.name, - - timing: { - monday: t.monday || "", - tuesday: t.tuesday || "", - wednesday: t.wednesday || "", - thursday: t.thursday || "", - friday: t.friday || "", - saturday: t.saturday || "", - sunday: t.sunday || "", - additional: t.additional || "", - }, - }; - }), + departments: doctor.departments.map((d) => ({ + departmentId: d.department.departmentId, + departmentName: d.department.name, + timing: d.timing || {}, + })), }; res.status(200).json({ From fb298cb8469aac7782fc156cf9a904c6f6094d14 Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Wed, 8 Apr 2026 16:44:41 +0530 Subject: [PATCH 3/3] fix: add JWT middleware to private API routes --- backend/src/routes/academicsResearch.routes.js | 4 ++-- backend/src/routes/appointment.routes.js | 6 +++--- backend/src/routes/candidate.routes.js | 12 ++++++------ backend/src/routes/career.routes.js | 6 +++--- backend/src/routes/department.routes.js | 2 ++ backend/src/routes/doctor.routes.js | 4 +++- backend/src/routes/inquiry.routes.js | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/backend/src/routes/academicsResearch.routes.js b/backend/src/routes/academicsResearch.routes.js index 712afbd..77a698e 100644 --- a/backend/src/routes/academicsResearch.routes.js +++ b/backend/src/routes/academicsResearch.routes.js @@ -11,8 +11,8 @@ import jwtAuthMiddleware from "../middleware/auth.js"; const router = express.Router(); router.post("/", createAcademicsResearch); -router.get("/getAll", getAcademicsResearch); -router.get("/:id", getSingleAcademicsResearch); +router.get("/getAll", jwtAuthMiddleware, getAcademicsResearch); +router.get("/:id", jwtAuthMiddleware, getSingleAcademicsResearch); router.delete("/:id", jwtAuthMiddleware, deleteAcademicsResearch); export default router; diff --git a/backend/src/routes/appointment.routes.js b/backend/src/routes/appointment.routes.js index becd07c..3374c9e 100644 --- a/backend/src/routes/appointment.routes.js +++ b/backend/src/routes/appointment.routes.js @@ -13,11 +13,11 @@ const router = express.Router(); /* PUBLIC */ -router.get("/getall", getAppointments); +router.get("/getall", jwtAuthMiddleware, getAppointments); router.post("/", createAppointment); -router.get("/:id", getAppointment); -router.patch("/:id", updateAppointment); +router.get("/:id", jwtAuthMiddleware, getAppointment); +router.patch("/:id", jwtAuthMiddleware, updateAppointment); router.delete("/:id", jwtAuthMiddleware, deleteAppointment); export default router; diff --git a/backend/src/routes/candidate.routes.js b/backend/src/routes/candidate.routes.js index 72e1dba..b9bff93 100644 --- a/backend/src/routes/candidate.routes.js +++ b/backend/src/routes/candidate.routes.js @@ -13,13 +13,13 @@ import jwtAuthMiddleware from "../middleware/auth.js"; const router = express.Router(); /* PUBLIC */ - -router.get("/getAll", getCandidates); -router.get("/:id", getCandidate); -router.get("/career/:careerId", getCandidatesByCareer); - router.post("/", createCandidate); -router.patch("/:id", updateCandidate); + +router.get("/getAll", jwtAuthMiddleware, getCandidates); +router.get("/:id", jwtAuthMiddleware, getCandidate); +router.get("/career/:careerId", jwtAuthMiddleware, getCandidatesByCareer); + +router.patch("/:id", jwtAuthMiddleware, updateCandidate); router.delete("/:id", jwtAuthMiddleware, deleteCandidate); export default router; diff --git a/backend/src/routes/career.routes.js b/backend/src/routes/career.routes.js index b85346b..b90e2a3 100644 --- a/backend/src/routes/career.routes.js +++ b/backend/src/routes/career.routes.js @@ -10,8 +10,8 @@ const router = express.Router(); router.get("/getAll", getAllCareers); -router.post("/", createCareer); -router.patch("/:id", updateCareer); -router.delete("/:id", deleteCareer); +router.post("/", jwtAuthMiddleware, createCareer); +router.patch("/:id", jwtAuthMiddleware, updateCareer); +router.delete("/:id", jwtAuthMiddleware, deleteCareer); export default router; diff --git a/backend/src/routes/department.routes.js b/backend/src/routes/department.routes.js index af4510d..882e614 100644 --- a/backend/src/routes/department.routes.js +++ b/backend/src/routes/department.routes.js @@ -1,6 +1,7 @@ import express from "express"; import { getAllDepartments, + getDepartmentByName, createDepartment, updateDepartment, deleteDepartment, @@ -11,6 +12,7 @@ const router = express.Router(); // Public router.get("/getAll", getAllDepartments); +router.get("/search", getDepartmentByName); // Protected router.post("/", jwtAuthMiddleware, createDepartment); diff --git a/backend/src/routes/doctor.routes.js b/backend/src/routes/doctor.routes.js index c91db2c..c8309c1 100644 --- a/backend/src/routes/doctor.routes.js +++ b/backend/src/routes/doctor.routes.js @@ -7,6 +7,7 @@ import { getDoctorTimings, getDoctorTimingById, getDoctorByDoctorId, + getDoctorsByDepartmentId, } from "../controllers/doctor.controller.js"; import jwtAuthMiddleware from "../middleware/auth.js"; @@ -14,9 +15,10 @@ import jwtAuthMiddleware from "../middleware/auth.js"; const router = express.Router(); router.get("/getAll", getAllDoctors); -router.get("/:doctorId", getDoctorByDoctorId); +router.get("/search", getDoctorsByDepartmentId); router.get("/getTimings", getDoctorTimings); router.get("/getTimings/:doctorId", getDoctorTimingById); +router.get("/:doctorId", getDoctorByDoctorId); router.post("/", jwtAuthMiddleware, createDoctor); router.patch("/:doctorId", jwtAuthMiddleware, updateDoctor); diff --git a/backend/src/routes/inquiry.routes.js b/backend/src/routes/inquiry.routes.js index 8329198..59251b8 100644 --- a/backend/src/routes/inquiry.routes.js +++ b/backend/src/routes/inquiry.routes.js @@ -12,8 +12,8 @@ const router = express.Router(); router.post("/", createInquiry); -router.get("/getAll", getInquiries); -router.get("/:id", getInquiry); +router.get("/getAll", jwtAuthMiddleware, getInquiries); +router.get("/:id", jwtAuthMiddleware, getInquiry); router.delete("/:id", jwtAuthMiddleware, deleteInquiry); export default router;