|
|
@ -486,4 +486,53 @@ exports.getAllOffices = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getOfficeDetails = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let { officeName, city } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!officeName || !city) {
|
|
|
|
|
|
|
|
return reply.code(400).send({ message: "officeName and city are required." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Normalize whitespace and case
|
|
|
|
|
|
|
|
officeName = officeName.trim().replace(/\s+/g, ' ');
|
|
|
|
|
|
|
|
city = city.trim().replace(/\s+/g, ' ');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filters = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (officeName.toUpperCase() !== 'ALL') {
|
|
|
|
|
|
|
|
filters.officeName = { $regex: new RegExp(officeName.replace(/\s+/g, '\\s*'), 'i') };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (city.toUpperCase() !== 'ALL') {
|
|
|
|
|
|
|
|
filters.city = { $regex: new RegExp(city.replace(/\s+/g, '\\s*'), 'i') };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Query City collection
|
|
|
|
|
|
|
|
const cityResults = await City.find(filters).lean();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Query Branch collection
|
|
|
|
|
|
|
|
const branchResults = await Branch.find(filters).lean();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const combinedResults = [...cityResults, ...branchResults];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (combinedResults.length === 0) {
|
|
|
|
|
|
|
|
return reply.status(404).send({ message: "No office details found for the given filters." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
|
|
|
status_code: 200,
|
|
|
|
|
|
|
|
message: "Office details fetched successfully.",
|
|
|
|
|
|
|
|
data: combinedResults,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error("Error in getOfficeDetails:", error);
|
|
|
|
|
|
|
|
reply.status(500).send({
|
|
|
|
|
|
|
|
status_code: 500,
|
|
|
|
|
|
|
|
message: "Internal server error",
|
|
|
|
|
|
|
|
error: error.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|