ashok 2 months ago
commit 5760b4c548

@ -1371,23 +1371,24 @@ exports.getOffices = async (req, reply) => {
const filter = {}; const filter = {};
if (officeName && officeName !== 'ALL') { if (officeName && officeName !== 'ALL') {
// support multiple office names as comma-separated
const officeNames = officeName.split(',').map(name => name.trim()); const officeNames = officeName.split(',').map(name => name.trim());
filter.officeName = { $in: officeNames }; filter.officeName = { $in: officeNames };
} }
if (city && city !== 'ALL') { if (city && city !== 'ALL') {
// support multiple cities as comma-separated
const cities = city.split(',').map(c => c.trim()); const cities = city.split(',').map(c => c.trim());
filter.city = { $in: cities }; filter.city = { $in: cities };
} }
const offices = await Deparments.find(filter).lean(); 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({ reply.send({
status_code: 200, status_code: 200,
message: "Fetched successfully", message: "Fetched successfully",
data: offices, data: departmentNames,
}); });
} catch (error) { } catch (error) {
@ -1401,6 +1402,8 @@ exports.getOffices = async (req, reply) => {
}; };
// API route handler // API route handler
exports.getDepartmentsByCity = async (req, reply) => { exports.getDepartmentsByCity = async (req, reply) => {
try { try {

@ -667,7 +667,7 @@ module.exports = function (fastify, opts, next) {
fastify.route({ fastify.route({
method: "GET", method: "GET",
url: "/api/departmentNameList/:city", url: "/api/departmentNameList/:city/:officeName",
schema: { schema: {
tags: ["Department"], tags: ["Department"],
description: "Get a list of department names for a given city", description: "Get a list of department names for a given city",
@ -676,13 +676,13 @@ module.exports = function (fastify, opts, next) {
type: "object", type: "object",
properties: { properties: {
city: { type: "string" }, city: { type: "string" },
// officeName: { type: "string" }, officeName: { type: "string" },
}, },
required: ["city"], required: ["city"],
}, },
}, },
handler: departmentController.getDepartmentsByCity, handler: departmentController.getOffices,
}); });
fastify.route({ fastify.route({

Loading…
Cancel
Save