|
|
|
@ -1128,16 +1128,16 @@ const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
|
.select("departmentName -_id")
|
|
|
|
|
.lean();
|
|
|
|
|
|
|
|
|
|
return result.map(doc => doc.departmentName);
|
|
|
|
|
// Remove duplicate department names
|
|
|
|
|
return [...new Set(result.map(doc => doc.departmentName))];
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching departments by city:", error);
|
|
|
|
|
throw new Error("Error fetching departments by city.");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// API route handler
|
|
|
|
|
exports.getDepartmentsByCity = async (req, reply) => {
|
|
|
|
|
// API route handler
|
|
|
|
|
exports.getDepartmentsByCity = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { city } = req.params;
|
|
|
|
|
if (!city || city.trim() === "") {
|
|
|
|
@ -1155,4 +1155,5 @@ exports.getDepartmentsByCity = async (req, reply) => {
|
|
|
|
|
console.error("API Error:", error);
|
|
|
|
|
reply.status(500).send({ message: error.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|