|
|
|
@ -953,12 +953,16 @@ exports.getZonebasedLocations = async (req, reply) => {
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
const getDepartmentsByName = async (departmentName, city) => {
|
|
|
|
|
// Updated helper function that accepts all three parameters
|
|
|
|
|
const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
|
try {
|
|
|
|
|
const trimmedDepartment = departmentName.trim();
|
|
|
|
|
// Trim all parameters
|
|
|
|
|
const trimmedOfficeName = officeName.trim();
|
|
|
|
|
const trimmedCity = city.trim();
|
|
|
|
|
const trimmedDepartment = departmentName.trim();
|
|
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
|
officeName: { $regex: trimmedOfficeName, $options: "i" },
|
|
|
|
|
departmentName: { $regex: trimmedDepartment, $options: "i" },
|
|
|
|
|
city: { $regex: trimmedCity, $options: "i" }
|
|
|
|
|
};
|
|
|
|
@ -973,7 +977,7 @@ exports.getZonebasedLocations = async (req, reply) => {
|
|
|
|
|
console.error("Error fetching department data:", err);
|
|
|
|
|
throw new Error("Error fetching department data.");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// API Route
|
|
|
|
@ -981,19 +985,21 @@ exports.getZonebasedLocations = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
console.log("Request Params:", req.params); // Debugging log
|
|
|
|
|
|
|
|
|
|
let { departmentName, city } = req.params;
|
|
|
|
|
let { departmentName, city, officeName } = req.params;
|
|
|
|
|
|
|
|
|
|
if (!departmentName || !city) {
|
|
|
|
|
return reply.status(400).send({ message: "Department Name and City are required." });
|
|
|
|
|
if (!departmentName || !city || !officeName) {
|
|
|
|
|
return reply.status(400).send({ message: "Department Name, City, and Office Name are required." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
departmentName = departmentName.trim();
|
|
|
|
|
city = city.trim();
|
|
|
|
|
officeName = officeName.trim();
|
|
|
|
|
|
|
|
|
|
const departments = await getDepartmentsByName(departmentName, city);
|
|
|
|
|
// Note the order: officeName, city, departmentName
|
|
|
|
|
const departments = await getDepartmentsByName(officeName, city, departmentName);
|
|
|
|
|
|
|
|
|
|
if (departments.length === 0) {
|
|
|
|
|
return reply.status(404).send({ message: "No departments found for the specified name and city." });
|
|
|
|
|
return reply.status(404).send({ message: "No departments found for the specified parameters." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: departments });
|
|
|
|
|