From 11d02f6001cadb1235146182fb731b55707a2821 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Thu, 7 Aug 2025 16:40:49 +0530 Subject: [PATCH] Department names by city --- src/controllers/departmentController.js | 9 ++++++--- src/routes/departmentRoute.js | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index e1351fd0..4ec2db4c 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -1371,23 +1371,24 @@ exports.getOffices = async (req, reply) => { const filter = {}; if (officeName && officeName !== 'ALL') { - // support multiple office names as comma-separated const officeNames = officeName.split(',').map(name => name.trim()); filter.officeName = { $in: officeNames }; } if (city && city !== 'ALL') { - // support multiple cities as comma-separated const cities = city.split(',').map(c => c.trim()); filter.city = { $in: cities }; } const offices = await Deparments.find(filter).lean(); + // Extract only department names and remove duplicates + const departmentNames = [...new Set(offices.map(o => o.departmentName))]; + reply.send({ status_code: 200, message: "Fetched successfully", - data: offices, + data: departmentNames, }); } catch (error) { @@ -1400,6 +1401,8 @@ exports.getOffices = async (req, reply) => { } }; + + // API route handler exports.getDepartmentsByCity = async (req, reply) => { diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index d0f1f8e2..e4e59d81 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -667,7 +667,7 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "GET", - url: "/api/departmentNameList/:city", + url: "/api/departmentNameList/:city/:officeName", schema: { tags: ["Department"], description: "Get a list of department names for a given city", @@ -676,13 +676,13 @@ module.exports = function (fastify, opts, next) { type: "object", properties: { city: { type: "string" }, - // officeName: { type: "string" }, + officeName: { type: "string" }, }, required: ["city"], }, }, - handler: departmentController.getDepartmentsByCity, + handler: departmentController.getOffices, }); fastify.route({