ashok 2 months ago
commit 5760b4c548

@ -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) {
@ -1401,6 +1402,8 @@ exports.getOffices = async (req, reply) => {
};
// API route handler
exports.getDepartmentsByCity = async (req, reply) => {
try {

@ -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({

Loading…
Cancel
Save