|
|
@ -1134,24 +1134,82 @@ exports.getZonebasedLocations = async (req, reply) => {
|
|
|
|
// };
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// Updated helper function that accepts all three parameters
|
|
|
|
// Updated helper function that accepts all three parameters
|
|
|
|
|
|
|
|
// const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// // 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" }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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("Error fetching department data:", err);
|
|
|
|
|
|
|
|
// throw new Error("Error fetching department data.");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// API Route
|
|
|
|
|
|
|
|
// exports.getDepartments = async (req, reply) => {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// console.log("Request Params:", req.params); // Debugging log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let { departmentName, city, officeName } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 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 parameters." });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reply.send({ status_code: 200, data: departments });
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// console.error("API Error:", err);
|
|
|
|
|
|
|
|
// reply.status(500).send({ message: err.message });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Trim all parameters
|
|
|
|
const query = {};
|
|
|
|
const trimmedOfficeName = officeName.trim();
|
|
|
|
|
|
|
|
const trimmedCity = city.trim();
|
|
|
|
|
|
|
|
const trimmedDepartment = departmentName.trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
if (officeName && officeName.trim().toUpperCase() !== "ALL") {
|
|
|
|
officeName: { $regex: trimmedOfficeName, $options: "i" },
|
|
|
|
query.officeName = { $regex: officeName.trim(), $options: "i" };
|
|
|
|
departmentName: { $regex: trimmedDepartment, $options: "i" },
|
|
|
|
}
|
|
|
|
city: { $regex: trimmedCity, $options: "i" }
|
|
|
|
|
|
|
|
};
|
|
|
|
if (city && city.trim().toUpperCase() !== "ALL") {
|
|
|
|
|
|
|
|
query.city = { $regex: city.trim(), $options: "i" };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (departmentName && departmentName.trim().toUpperCase() !== "ALL") {
|
|
|
|
|
|
|
|
query.departmentName = { $regex: departmentName.trim(), $options: "i" };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log("MongoDB Query:", JSON.stringify(query, null, 2));
|
|
|
|
console.log("MongoDB Query:", JSON.stringify(query, null, 2));
|
|
|
|
|
|
|
|
|
|
|
|
const result = await Deparments.find(query).lean();
|
|
|
|
const result = await Deparments.find(query).lean();
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Query Result:", result);
|
|
|
|
console.log("Query Result:", result);
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error fetching department data:", err);
|
|
|
|
console.error("Error fetching department data:", err);
|
|
|
@ -1159,27 +1217,24 @@ const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// API Route
|
|
|
|
|
|
|
|
exports.getDepartments = async (req, reply) => {
|
|
|
|
exports.getDepartments = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
console.log("Request Params:", req.params); // Debugging log
|
|
|
|
console.log("Request Params:", req.params);
|
|
|
|
|
|
|
|
|
|
|
|
let { departmentName, city, officeName } = req.params;
|
|
|
|
let { departmentName, city, officeName } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
if (!departmentName || !city || !officeName) {
|
|
|
|
if (!departmentName || !city || !officeName) {
|
|
|
|
return reply.status(400).send({ message: "Department Name, City, and Office Name are required." });
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
|
|
|
message: "Department Name, City, and Office Name are required.",
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
departmentName = departmentName.trim();
|
|
|
|
|
|
|
|
city = city.trim();
|
|
|
|
|
|
|
|
officeName = officeName.trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Note the order: officeName, city, departmentName
|
|
|
|
|
|
|
|
const departments = await getDepartmentsByName(officeName, city, departmentName);
|
|
|
|
const departments = await getDepartmentsByName(officeName, city, departmentName);
|
|
|
|
|
|
|
|
|
|
|
|
if (departments.length === 0) {
|
|
|
|
if (departments.length === 0) {
|
|
|
|
return reply.status(404).send({ message: "No departments found for the specified parameters." });
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
|
|
|
message: "No departments found for the specified parameters.",
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: departments });
|
|
|
|
reply.send({ status_code: 200, data: departments });
|
|
|
@ -1191,7 +1246,6 @@ const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentNames = async () => {
|
|
|
|
const getDepartmentNames = async () => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const result = await Deparments.aggregate([
|
|
|
|
const result = await Deparments.aggregate([
|
|
|
|