ashok 2 months ago
commit 75b610bb1e

@ -1620,26 +1620,32 @@ exports.getOffices = async (req, reply) => {
const filter = {};
if (officeName && officeName !== 'ALL') {
// Apply officeName filter only if not ALL
if (officeName && officeName.toUpperCase() !== 'ALL') {
const officeNames = officeName.split(',').map(name =>
new RegExp(name.trim().replace(/\s+/g, '\\s*'), 'i') // fuzzy match
);
filter.officeName = { $in: officeNames };
}
if (city && city !== 'ALL') {
// Apply city filter only if not ALL
if (city && city.toUpperCase() !== 'ALL') {
const cities = city.split(',').map(name =>
new RegExp(name.trim().replace(/\s+/g, '\\s*'), 'i')
);
filter.city = { $in: cities };
}
console.log("officeName",officeName)
console.log("city",city)
console.log("Filter being applied:", filter);
// Fetch offices from DB
const offices = await Deparments.find(filter).lean();
// Extract only department names and remove duplicates
const departmentNames = [...new Set(offices.map(o => o.departmentName))];
// Extract unique department names
let departmentNames = [...new Set(offices.map(o => o.departmentName))];
// Always include "ALL" at the start of the list
departmentNames = ['ALL', ...departmentNames];
reply.send({
status_code: 200,
@ -1657,6 +1663,7 @@ exports.getOffices = async (req, reply) => {
}
};
// exports.getOffices = async (req, reply) => {
// try {
// const { officeName, city } = req.params;

Loading…
Cancel
Save