changes on Get all department details fetch the managers list

master^2
Bhaskar 2 months ago
parent e734e01014
commit 0c7147392e

@ -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");
// 1Check Branch schema for match
// 1Branch 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();
// 3Get all departments for this officeName & city
// 3Departments
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;

Loading…
Cancel
Save