diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index 6e7a56d0..f8b7eb0f 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -992,69 +992,6 @@ exports.getZonebasedLocations = async (req, reply) => { } }; - const getZonesByCityAndOffice = async (city, officeName) => { - try { - const result = await Zone.aggregate([ - { - $project: { - city: { $trim: { input: "$city" } }, // Trim city field - officeName: { $trim: { input: "$officeName" } }, // Trim officeName field - zone: 1 // Keep zone field - } - }, - { - $match: { - city: { $regex: `^${city.trim()}$`, $options: "i" }, // Case-insensitive match for city - officeName: { $regex: `^${officeName.trim()}$`, $options: "i" } // Case-insensitive match for officeName - } - }, - { - $group: { - _id: { city: { $toUpper: "$city" }, officeName: { $toUpper: "$officeName" } }, // Normalize city and officeName - zones: { $addToSet: "$zone" } // Collect unique zones - } - }, - { - $project: { - _id: 0, // Exclude _id - city: "$_id.city", // Return city name - officeName: "$_id.officeName", // Return officeName - zones: 1 // Return collected zones - } - } - ]); - - // Add "ALL" to the zones array and sort it - result.forEach(item => { - item.zones = ["ALL", ...new Set(item.zones)].sort((a, b) => (a === "ALL" ? -1 : a - b)); - }); - - return result; - } catch (err) { - console.error("Error fetching zones:", err); - throw new Error("Error fetching zones."); - } - }; - - exports.getZonesByCityAndOffice = async (req, reply) => { - try { - const { city, officeName } = req.params; - - if (!city || city.trim() === "" || !officeName || officeName.trim() === "") { - return reply.status(400).send({ message: "City and officeName are required." }); - } - - const zones = await getZonesByCityAndOffice(city.trim(), officeName.trim()); // Trim inputs - - if (zones.length === 0) { - return reply.status(404).send({ message: "No zones found for the specified city and officeName." }); - } - - reply.send({ status_code: 200, data: zones }); - } catch (err) { - reply.status(500).send({ message: err.message }); - } - }; diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index 9753a1af..49082a0a 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -430,23 +430,21 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "GET", - url: "/api/zonebasedcity/:city/:officeName", + url: "/api/zonebasedcity/:city", schema: { tags: ["Department"], - description: "Get the zones by city and office name", - summary: "Get the zones by city and office name", + description: "Get the zones by city", + summary: "Get the zones by city", params: { type: "object", properties: { - city: { type: "string" }, - officeName: { type: "string" }, + city: { type: "string" }, }, - required: ["city", "officeName"] }, }, - handler: departmentController.getZonesByCityAndOffice + handler:departmentController.getZonesByCity }); - + fastify.route({ method: "GET", url: "/api/departmentNamebaselist/:officeName/:city/:departmentName",