ashok 1 month ago
commit b3ed241831

@ -590,9 +590,9 @@ exports.getTeamMembers = async (request, reply) => {
exports.getAllDepartments = async (request, reply) => {
try {
const { officeName, city } = request.params;
const { officeName } = request.params;
if (!officeName || !city) {
if (!officeName ) {
return reply.status(400).send({
simplydata: {
error: true,
@ -607,28 +607,28 @@ exports.getAllDepartments = async (request, reply) => {
"i"
);
// If city === "ALL" → no filter, else regex
const cityFilter =
city.toUpperCase() === "ALL"
? {}
: { city: new RegExp(city.trim().replace(/\s+/g, "\\s*"), "i") };
// // If city === "ALL" → no filter, else regex
// const cityFilter =
// city.toUpperCase() === "ALL"
// ? {}
// : { city: new RegExp(city.trim().replace(/\s+/g, "\\s*"), "i") };
// 1⃣ Branch match (all branches for that officeName)
const branchMatches = await Branch.find({
officeName: nameRegex,
...cityFilter,
//...cityFilter,
}).lean();
// 2⃣ City (headOffice) match
const cityMatches = await City.find({
officeName: nameRegex,
...cityFilter,
//...cityFilter,
}).lean();
// 3⃣ Departments (all matching officeName + city filter)
let departments = await Deparments.find({
officeName: nameRegex,
...cityFilter,
// ...cityFilter,
}).lean();
// Add contactPerson to departments
@ -642,12 +642,12 @@ exports.getAllDepartments = async (request, reply) => {
// 🔹 Build response
const responseData = [{ firstName: "Self" },{ reportingManager: "Self" }];
branchMatches.forEach((br) =>
responseData.push({
officeType: "branch",
...br,
})
);
// branchMatches.forEach((br) =>
// responseData.push({
// officeType: "branch",
// ...br,
// })
// );
// cityMatches.forEach((ho) =>
// responseData.push({

@ -34,7 +34,7 @@ module.exports = function (fastify, opts, next) {
handler: installationController.createTeamMember,
});
fastify.get("/api/getAllDepartments/:officeName/:city", {
fastify.get("/api/getAllDepartments/:officeName", {
schema: {
description: "Get full department details by department name",
tags: ["Admin"],
@ -43,7 +43,7 @@ fastify.get("/api/getAllDepartments/:officeName/:city", {
type: "object",
properties: {
officeName: { type: "string", },
city: { type: "string", },
// city: { type: "string", },
},
// required: ["departmentName"],

Loading…
Cancel
Save