get team members by departmentId

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

@ -99,28 +99,28 @@ exports.createTeamMember = async (request, reply) => {
exports.getTeamMembers = async (request, reply) => {
try {
const { installationId } = request.params; // Get installationId from request params
const { departmentId } = request.params; // ✅ Get departmentId from request params
// Check if installation exists
const installation = await Install.findOne({ installationId });
// ✅ Find the department using departmentId
const department = await Deparments.findOne({ departmentId });
if (!installation) {
if (!department) {
return reply.status(404).send({
simplydata: {
error: true,
message: "Installation not found",
message: "Department not found",
},
});
}
// Extract team members
const teamMembers = installation.team_member.team_member;
// Extract team members from department schema
const teamMembers = department.team_member.team_member;
return reply.send({
simplydata: {
error: false,
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,
});
fastify.get("/api/getTeamMembers/:installationId", {
fastify.get("/api/getTeamMembers/:departmentId", {
schema: {
description: "Get all team members under a specific installation",
description: "Get all team members under a specific department",
tags: ["Installation"],
summary: "Get Team Members",
summary: "Get Team Members by Department ID",
params: {
type: "object",
properties: {
installationId: {
departmentId: {
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
});

Loading…
Cancel
Save