get team members by departmentId

master^2
Bhaskar 8 months ago
parent a4e8253945
commit 762c6e0c07

@ -99,28 +99,28 @@ exports.createTeamMember = async (request, reply) => {
exports.getTeamMembers = async (request, reply) => { exports.getTeamMembers = async (request, reply) => {
try { try {
const { installationId } = request.params; // Get installationId from request params const { departmentId } = request.params; // ✅ Get departmentId from request params
// Check if installation exists // ✅ Find the department using departmentId
const installation = await Install.findOne({ installationId }); const department = await Deparments.findOne({ departmentId });
if (!installation) { if (!department) {
return reply.status(404).send({ return reply.status(404).send({
simplydata: { simplydata: {
error: true, error: true,
message: "Installation not found", message: "Department not found",
}, },
}); });
} }
// Extract team members // Extract team members from department schema
const teamMembers = installation.team_member.team_member; const teamMembers = department.team_member.team_member;
return reply.send({ return reply.send({
simplydata: { simplydata: {
error: false, error: false,
message: "Team members retrieved successfully", message: "Team members retrieved successfully",
teamMembers, // Return the list of team members teamMembers, // Return the list of team members
}, },
}); });

@ -26,22 +26,21 @@ module.exports = function (fastify, opts, next) {
handler: installationController.createTeamMember, handler: installationController.createTeamMember,
}); });
fastify.get("/api/getTeamMembers/:installationId", { fastify.get("/api/getTeamMembers/:departmentId", {
schema: { schema: {
description: "Get all team members under a specific installation", description: "Get all team members under a specific department",
tags: ["Installation"], tags: ["Installation"],
summary: "Get Team Members", summary: "Get Team Members by Department ID",
params: { params: {
type: "object", type: "object",
properties: { properties: {
installationId: { departmentId: {
type: "string", type: "string",
description: "Installation ID to fetch team members from" description: "Department ID to fetch team members from"
} }
}, },
required: ["installationId"] required: ["departmentId"]
}, },
}, },
handler: installationController.getTeamMembers handler: installationController.getTeamMembers
}); });

Loading…
Cancel
Save