|
|
@ -1419,20 +1419,25 @@ exports.getCitiesByOfficeName = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
exports.getOffices = async (req, reply) => {
|
|
|
|
exports.getOffices = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { officeName, city } = req.params;
|
|
|
|
let { officeName, city } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
// Build dynamic filter
|
|
|
|
|
|
|
|
const filter = {};
|
|
|
|
const filter = {};
|
|
|
|
|
|
|
|
|
|
|
|
if (officeName && officeName !== 'ALL') {
|
|
|
|
if (officeName && officeName !== 'ALL') {
|
|
|
|
const officeNames = officeName.split(',').map(name => name.trim());
|
|
|
|
const officeNames = officeName.split(',').map(name =>
|
|
|
|
|
|
|
|
new RegExp(name.trim().replace(/\s+/g, '\\s*'), 'i') // fuzzy match
|
|
|
|
|
|
|
|
);
|
|
|
|
filter.officeName = { $in: officeNames };
|
|
|
|
filter.officeName = { $in: officeNames };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (city && city !== 'ALL') {
|
|
|
|
if (city && city !== 'ALL') {
|
|
|
|
const cities = city.split(',').map(c => c.trim());
|
|
|
|
const cities = city.split(',').map(name =>
|
|
|
|
|
|
|
|
new RegExp(name.trim().replace(/\s+/g, '\\s*'), 'i')
|
|
|
|
|
|
|
|
);
|
|
|
|
filter.city = { $in: cities };
|
|
|
|
filter.city = { $in: cities };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("officeName",officeName)
|
|
|
|
|
|
|
|
console.log("city",city)
|
|
|
|
|
|
|
|
|
|
|
|
const offices = await Deparments.find(filter).lean();
|
|
|
|
const offices = await Deparments.find(filter).lean();
|
|
|
|
|
|
|
|
|
|
|
@ -1455,6 +1460,50 @@ exports.getOffices = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.getOffices = async (req, reply) => {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// const { officeName, city } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const filter = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (officeName && officeName !== 'ALL') {
|
|
|
|
|
|
|
|
// const officeNames = officeName.split(',').map(name =>
|
|
|
|
|
|
|
|
// new RegExp(`^${name.trim()}$`, 'i')
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// filter.officeName = { $in: officeNames };
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// console.log("officeName",officeName)
|
|
|
|
|
|
|
|
// if (city && city !== 'ALL') {
|
|
|
|
|
|
|
|
// const cities = city.split(',').map(c =>
|
|
|
|
|
|
|
|
// new RegExp(`^${c.trim()}$`, 'i')
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// filter.city = { $in: cities };
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// console.log("officeName",officeName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const offices = await Deparments.find(filter).lean();
|
|
|
|
|
|
|
|
// console.log(offices, "offices");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const departmentNames = [...new Set(offices.map(o => o.departmentName))];
|
|
|
|
|
|
|
|
// console.log(departmentNames, "departmentNames");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reply.send({
|
|
|
|
|
|
|
|
// status_code: 200,
|
|
|
|
|
|
|
|
// message: "Fetched successfully",
|
|
|
|
|
|
|
|
// data: departmentNames,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
|
|
|
// console.error("Error in getOffices:", error);
|
|
|
|
|
|
|
|
// reply.code(500).send({
|
|
|
|
|
|
|
|
// status_code: 500,
|
|
|
|
|
|
|
|
// message: "Internal server error",
|
|
|
|
|
|
|
|
// error: error.message,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|