|
|
@ -1433,47 +1433,76 @@ exports.getZonesByCityAndOffice = async (req, reply) => {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
// const getDepartmentsByName = async (officeName, city, departmentName) => {
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
const query = {};
|
|
|
|
// const query = {};
|
|
|
|
|
|
|
|
|
|
|
|
if (officeName && officeName.trim().toUpperCase() !== "ALL") {
|
|
|
|
// if (officeName && officeName.trim().toUpperCase() !== "ALL") {
|
|
|
|
query.officeName = { $regex: officeName.trim(), $options: "i" };
|
|
|
|
// query.officeName = { $regex: officeName.trim(), $options: "i" };
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (city && city.trim().toUpperCase() !== "ALL") {
|
|
|
|
// if (city && city.trim().toUpperCase() !== "ALL") {
|
|
|
|
query.city = { $regex: city.trim(), $options: "i" };
|
|
|
|
// query.city = { $regex: city.trim(), $options: "i" };
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (departmentName && departmentName.trim().toUpperCase() !== "ALL") {
|
|
|
|
// if (departmentName && departmentName.trim().toUpperCase() !== "ALL") {
|
|
|
|
query.departmentName = { $regex: departmentName.trim(), $options: "i" };
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// console.log("Query Result:", result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return result;
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// console.error("Error fetching department data:", err);
|
|
|
|
|
|
|
|
// throw new Error("Error fetching department data.");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.getDepartments = async (req, reply) => {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// console.log("Request Params:", req.params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let { departmentName, city, officeName } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!departmentName || !city || !officeName) {
|
|
|
|
|
|
|
|
// return reply.status(400).send({
|
|
|
|
|
|
|
|
// message: "Department Name, City, and Office Name are required.",
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 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.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getDepartments = async (req, reply) => {
|
|
|
|
exports.getDepartments = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
console.log("Request Params:", req.params);
|
|
|
|
console.log("Request Params:", req.params);
|
|
|
|
|
|
|
|
|
|
|
|
let { departmentName, city, officeName } = req.params;
|
|
|
|
let { departmentName, city, officeName, employeeType } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
if (!departmentName || !city || !officeName) {
|
|
|
|
if (!departmentName || !city || !officeName || !employeeType) {
|
|
|
|
return reply.status(400).send({
|
|
|
|
return reply.status(400).send({
|
|
|
|
message: "Department Name, City, and Office Name are required.",
|
|
|
|
message: "Department Name, City, Office Name, and Employee Type are required.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const departments = await getDepartmentsByName(officeName, city, departmentName);
|
|
|
|
const departments = await getDepartmentsByName(officeName, city, departmentName, employeeType);
|
|
|
|
|
|
|
|
|
|
|
|
if (departments.length === 0) {
|
|
|
|
if (departments.length === 0) {
|
|
|
|
return reply.status(404).send({
|
|
|
|
return reply.status(404).send({
|
|
|
@ -1488,6 +1517,37 @@ exports.getDepartments = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentsByName = async (officeName, city, departmentName, employeeType) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const query = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (officeName && officeName.trim().toUpperCase() !== "ALL") {
|
|
|
|
|
|
|
|
query.officeName = { $regex: officeName.trim(), $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" };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (employeeType && employeeType.trim().toUpperCase() !== "ALL") {
|
|
|
|
|
|
|
|
query.employeeType = { $regex: `^${employeeType.trim()}$`, $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.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDepartmentNames = async () => {
|
|
|
|
const getDepartmentNames = async () => {
|
|
|
|