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