|
|
|
@ -735,4 +735,34 @@ exports.addDepartment = async (request, reply) => {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentsByName = async (departmentName) => {
|
|
|
|
|
try {
|
|
|
|
|
const result = await Deparments.find({
|
|
|
|
|
departmentName: { $regex: `^${departmentName}$`, $options: "i" }, // Case-insensitive search
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
throw new Error("Error fetching department data.");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// API Route
|
|
|
|
|
exports.getDepartments = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { departmentName } = req.params; // Get departmentName from request params
|
|
|
|
|
|
|
|
|
|
if (!departmentName) {
|
|
|
|
|
return reply.status(400).send({ message: "Department Name is required." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const departments = await getDepartmentsByName(departmentName);
|
|
|
|
|
reply.send({ status_code: 200, data: departments });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|