diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 69429c1f..df088c29 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -353,33 +353,30 @@ exports.getAllDepartments = async (request, reply) => { }); } - // Prepare case-insensitive regex for matching - const nameRegex = new RegExp(`^${officeName.trim()}$`, "i"); - const cityRegex = new RegExp(`^${city.trim()}$`, "i"); + // Case-insensitive regex without start/end anchors to avoid trailing space issues + const nameRegex = new RegExp(officeName.trim().replace(/\s+/g, "\\s*"), "i"); + const cityRegex = new RegExp(city.trim().replace(/\s+/g, "\\s*"), "i"); - // 1️⃣ Check Branch schema for match + // 1️⃣ Branch match const branchMatch = await Branch.findOne({ officeName: nameRegex, city: cityRegex, }).lean(); - - // 2️⃣ Check City schema for match + // 2️⃣ City match const cityMatch = await City.findOne({ officeName: nameRegex, city: cityRegex, }).lean(); - // 3️⃣ Get all departments for this officeName & city + // 3️⃣ Departments const departments = await Deparments.find({ officeName: nameRegex, city: cityRegex, }).lean(); - // Start response data with "Self" const responseData = [{ firstName: "Self" }]; - // If a Branch or City record is found, add it right after "Self" if (branchMatch) { responseData.push({ officeType: "branch", @@ -393,7 +390,6 @@ exports.getAllDepartments = async (request, reply) => { }); } - // Then add department docs responseData.push(...departments); return reply.send({ @@ -419,6 +415,7 @@ exports.getAllDepartments = async (request, reply) => { }; + exports.assignTeamMemberToQuotation = async (request, reply) => { try { const { installationId } = request.params;