|
|
@ -415,29 +415,77 @@ exports.createTeamMember = async (req, reply) => {
|
|
|
|
// };
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// Controller
|
|
|
|
// Controller
|
|
|
|
|
|
|
|
// exports.getTeamMembers = async (request, reply) => {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// const { departmentId, officeName, city } = request.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Make regex tolerate spaces
|
|
|
|
|
|
|
|
// const department = await Deparments.findOne({
|
|
|
|
|
|
|
|
// departmentId,
|
|
|
|
|
|
|
|
// officeName: { $regex: new RegExp(`^\\s*${officeName.trim()}\\s*$`, "i") },
|
|
|
|
|
|
|
|
// city: { $regex: new RegExp(`^\\s*${city.trim()}\\s*$`, "i") }
|
|
|
|
|
|
|
|
// }).lean();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log("department", department);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!department) {
|
|
|
|
|
|
|
|
// return reply.status(404).send({
|
|
|
|
|
|
|
|
// simplydata: {
|
|
|
|
|
|
|
|
// error: true,
|
|
|
|
|
|
|
|
// message: "Department not found for given office and city",
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const teamMembers = department.team_member?.team_member || [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return reply.send({
|
|
|
|
|
|
|
|
// simplydata: {
|
|
|
|
|
|
|
|
// error: false,
|
|
|
|
|
|
|
|
// message: "Team members retrieved successfully",
|
|
|
|
|
|
|
|
// teamMembers,
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// console.error("Error fetching team members:", err);
|
|
|
|
|
|
|
|
// reply.status(500).send({
|
|
|
|
|
|
|
|
// simplydata: {
|
|
|
|
|
|
|
|
// error: true,
|
|
|
|
|
|
|
|
// message: "Internal server error",
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTeamMembers = async (request, reply) => {
|
|
|
|
exports.getTeamMembers = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { departmentId, officeName, city } = request.params;
|
|
|
|
const { departmentId, officeName, city } = request.params;
|
|
|
|
|
|
|
|
|
|
|
|
// Make regex tolerate spaces
|
|
|
|
// Build query dynamically
|
|
|
|
const department = await Deparments.findOne({
|
|
|
|
const query = {
|
|
|
|
departmentId,
|
|
|
|
departmentId,
|
|
|
|
officeName: { $regex: new RegExp(`^\\s*${officeName.trim()}\\s*$`, "i") },
|
|
|
|
officeName: { $regex: new RegExp(`^\\s*${officeName.trim()}\\s*$`, "i") },
|
|
|
|
city: { $regex: new RegExp(`^\\s*${city.trim()}\\s*$`, "i") }
|
|
|
|
};
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("department", department);
|
|
|
|
// Only add city filter if city !== "ALL"
|
|
|
|
|
|
|
|
if (city && city.toUpperCase() !== "ALL") {
|
|
|
|
|
|
|
|
query.city = { $regex: new RegExp(`^\\s*${city.trim()}\\s*$`, "i") };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!department) {
|
|
|
|
const departments = await Deparments.find(query).lean();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!departments.length) {
|
|
|
|
return reply.status(404).send({
|
|
|
|
return reply.status(404).send({
|
|
|
|
simplydata: {
|
|
|
|
simplydata: {
|
|
|
|
error: true,
|
|
|
|
error: true,
|
|
|
|
message: "Department not found for given office and city",
|
|
|
|
message: "No departments found for given filters",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const teamMembers = department.team_member?.team_member || [];
|
|
|
|
// Collect team members from all matching departments
|
|
|
|
|
|
|
|
const teamMembers = departments.flatMap(dep => dep.team_member?.team_member || []);
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
return reply.send({
|
|
|
|
simplydata: {
|
|
|
|
simplydata: {
|
|
|
@ -459,7 +507,6 @@ exports.getTeamMembers = async (request, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.getAllDepartments = async (request, reply) => {
|
|
|
|
// exports.getAllDepartments = async (request, reply) => {
|
|
|
|
// try {
|
|
|
|
// try {
|
|
|
|
// const { officeName, city } = request.params;
|
|
|
|
// const { officeName, city } = request.params;
|
|
|
|