|
|
|
@ -1000,22 +1000,25 @@ exports.getZonebasedLocations = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
exports.getCitiesByOfficeName = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { officeName } = req.params;
|
|
|
|
|
let { officeName } = req.params;
|
|
|
|
|
|
|
|
|
|
// Case-insensitive search
|
|
|
|
|
const regexOfficeName = new RegExp(`^${officeName}$`, "i");
|
|
|
|
|
// Trim and normalize spaces
|
|
|
|
|
officeName = officeName.trim().replace(/\s+/g, ' '); // Replace multiple spaces with one
|
|
|
|
|
const regexOfficeName = new RegExp(officeName.replace(/\s+/g, '\\s*'), "i");
|
|
|
|
|
|
|
|
|
|
// Query both collections
|
|
|
|
|
const cityResults = await City.find({ officeName: regexOfficeName }).select("city -_id").lean();
|
|
|
|
|
const branchResults = await Branch.find({ officeName: regexOfficeName }).select("city -_id").lean();
|
|
|
|
|
// Debugging: Check all available office names in DB
|
|
|
|
|
console.log("All Cities with Office Name:", await City.find().select("officeName city").lean());
|
|
|
|
|
console.log("All Branches with Office Name:", await Branch.find().select("officeName city").lean());
|
|
|
|
|
|
|
|
|
|
// Query both collections with case-insensitive regex
|
|
|
|
|
const cityResults = await City.find({ officeName: { $regex: officeName, $options: "i" } }).select("city -_id").lean();
|
|
|
|
|
const branchResults = await Branch.find({ officeName: { $regex: officeName, $options: "i" } }).select("city -_id").lean();
|
|
|
|
|
|
|
|
|
|
// Extract and merge unique city names
|
|
|
|
|
const cityNames = [...new Set([...cityResults.map(c => c.city), ...branchResults.map(b => b.city)])];
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
console.log("City Results:", cityResults);
|
|
|
|
|
console.log("Branch Results:", branchResults);
|
|
|
|
|
|
|
|
|
|
console.log("Final City Results:", cityNames);
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: cityNames });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching cities:", err);
|
|
|
|
|