master^2
Bhaskar 2 months ago
parent d19e28ea70
commit e734e01014

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

Loading…
Cancel
Save