|
|
|
@ -939,35 +939,72 @@ exports.getZonebasedLocations = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentsByName = async (departmentName) => {
|
|
|
|
|
// const getDepartmentsByName = async (departmentName, city) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const result = await Deparments.find({
|
|
|
|
|
// departmentName: { $regex: `^${departmentName.trim()}$`, $options: "i" }, // Case-insensitive search
|
|
|
|
|
// city: { $regex: `^${city.trim()}$`, $options: "i" }, // Case-insensitive search
|
|
|
|
|
// }).lean(); // Convert to plain JSON
|
|
|
|
|
|
|
|
|
|
// return result;
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// console.error("Error fetching department data:", err);
|
|
|
|
|
// throw new Error("Error fetching department data.");
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
const getDepartmentsByName = async (departmentName, city) => {
|
|
|
|
|
try {
|
|
|
|
|
const result = await Deparments.find({
|
|
|
|
|
departmentName: { $regex: `^${departmentName}$`, $options: "i" }, // Case-insensitive search
|
|
|
|
|
});
|
|
|
|
|
const trimmedDepartment = departmentName.trim();
|
|
|
|
|
const trimmedCity = city.trim();
|
|
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
|
departmentName: { $regex: trimmedDepartment, $options: "i" },
|
|
|
|
|
city: { $regex: trimmedCity, $options: "i" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
console.log("MongoDB Query:", JSON.stringify(query, null, 2));
|
|
|
|
|
|
|
|
|
|
const result = await Deparments.find(query).lean();
|
|
|
|
|
|
|
|
|
|
console.log("Query Result:", result);
|
|
|
|
|
return result;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
console.error("Error fetching department data:", 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
|
|
|
|
|
console.log("Request Params:", req.params); // Debugging log
|
|
|
|
|
|
|
|
|
|
let { departmentName, city } = req.params;
|
|
|
|
|
|
|
|
|
|
if (!departmentName) {
|
|
|
|
|
return reply.status(400).send({ message: "Department Name is required." });
|
|
|
|
|
if (!departmentName || !city) {
|
|
|
|
|
return reply.status(400).send({ message: "Department Name and City are required." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
departmentName = departmentName.trim();
|
|
|
|
|
city = city.trim();
|
|
|
|
|
|
|
|
|
|
const departments = await getDepartmentsByName(departmentName, city);
|
|
|
|
|
|
|
|
|
|
if (departments.length === 0) {
|
|
|
|
|
return reply.status(404).send({ message: "No departments found for the specified name and city." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const departments = await getDepartmentsByName(departmentName);
|
|
|
|
|
reply.send({ status_code: 200, data: departments });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("API Error:", err);
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentNames = async () => {
|
|
|
|
|
try {
|
|
|
|
|