|
|
@ -97,4 +97,152 @@ exports.createTeamMember = async (request, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTeamMembers = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { installationId } = request.params; // Get installationId from request params
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if installation exists
|
|
|
|
|
|
|
|
const installation = await Install.findOne({ installationId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!installation) {
|
|
|
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Installation not found",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extract team members
|
|
|
|
|
|
|
|
const teamMembers = installation.team_member.team_member;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
message: "Team members retrieved successfully",
|
|
|
|
|
|
|
|
teamMembers, // Return the list of team members
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error("Error fetching team members:", err);
|
|
|
|
|
|
|
|
reply.status(500).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Internal server error",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.editTeamMember = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { installationId, teamMemberId } = request.params;
|
|
|
|
|
|
|
|
const updateData = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the installation
|
|
|
|
|
|
|
|
const installation = await Install.findOne({ installationId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!installation) {
|
|
|
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Installation not found",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the team member
|
|
|
|
|
|
|
|
let teamMember = installation.team_member.team_member.find(
|
|
|
|
|
|
|
|
(member) => member.teamMemberId === teamMemberId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!teamMember) {
|
|
|
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Team member not found",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update fields
|
|
|
|
|
|
|
|
Object.assign(teamMember, updateData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save changes
|
|
|
|
|
|
|
|
await installation.markModified("team_member.team_member");
|
|
|
|
|
|
|
|
await installation.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
message: "Team member updated successfully",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error("Error updating team member:", err);
|
|
|
|
|
|
|
|
reply.status(500).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Internal server error",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deleteTeamMember = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { installationId, teamMemberId } = request.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the installation
|
|
|
|
|
|
|
|
const installation = await Install.findOne({ installationId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!installation) {
|
|
|
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Installation not found",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find index of the team member
|
|
|
|
|
|
|
|
const memberIndex = installation.team_member.team_member.findIndex(
|
|
|
|
|
|
|
|
(member) => member.teamMemberId === teamMemberId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (memberIndex === -1) {
|
|
|
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Team member not found",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the team member from the array
|
|
|
|
|
|
|
|
installation.team_member.team_member.splice(memberIndex, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save changes
|
|
|
|
|
|
|
|
await installation.markModified("team_member.team_member");
|
|
|
|
|
|
|
|
await installation.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
message: "Team member deleted successfully",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error("Error deleting team member:", err);
|
|
|
|
|
|
|
|
reply.status(500).send({
|
|
|
|
|
|
|
|
simplydata: {
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
message: "Internal server error",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|