get city based on office name

master^2
Bhaskar 8 months ago
parent a8fdd451e8
commit 9c3ece1952

@ -997,3 +997,29 @@ exports.getZonebasedLocations = async (req, reply) => {
} }
}; };
exports.getCitiesByOfficeName = async (req, reply) => {
try {
const { officeName } = req.params;
// Case-insensitive search
const regexOfficeName = new RegExp(`^${officeName}$`, "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();
// 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);
reply.send({ status_code: 200, data: cityNames });
} catch (err) {
console.error("Error fetching cities:", err);
reply.send({ error: err.message });
}
};

@ -565,5 +565,28 @@ module.exports = function (fastify, opts, next) {
handler: departmentController.editBranch, handler: departmentController.editBranch,
}); });
fastify.get("/api/getCitiesByOfficeName/:officeName", {
schema: {
tags: ["Department"],
description: "This is for Get cities by OfficeName Data",
summary: "This is to Get cities by OfficeName Data",
params: {
type: "object",
properties: {
officeName: {
type: "string",
description: "officeName",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: departmentController.getCitiesByOfficeName,
});
next(); next();
}; };
Loading…
Cancel
Save