Merged PR 964: UserStory EMP005 Update Designation

Related work items: #949
This commit is contained in:
Tinu Johnson
2026-04-16 09:42:01 +05:30
committed by Joel Thomas
9 changed files with 95 additions and 30 deletions
@@ -42,6 +42,11 @@ std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
return m_employeeManagementService->getCurrentEmployee();
}
bool ZenvyController::updateDesignation(const std::string& id,Enums::EmployeeDesignation designation)
{
return m_employeeManagementService->updateDesignation(id,designation);
}
//Payslip Management
void ZenvyController::updateSalary(const std::string& employeeId, double basicSalary, double houseRentAllowance, double foodAllowance, double employeePFContribution, double employerPFContribution)
{
@@ -50,7 +50,7 @@ public:
std::shared_ptr<const Employee> getCurrentEmployee();
void updateProfile(const std::string&,const std::string&);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
bool updateDesignation(const std::string&,Enums::EmployeeDesignation);
template <typename ...Types>
Employees getEmployees(Types ...types)
{
@@ -131,6 +131,24 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
return true;
}
bool EmployeeManagementService::updateDesignation(const std::string& id, Enums::EmployeeDesignation designation)
{
auto& authenticatedEmployee = m_dataStore.getAuthenticatedEmployee();
util::enforceAuthorization(authenticatedEmployee->getEmployeeType(), Enums::EmployeeType::ADMIN, Enums::EmployeeType::HR);
std::map<std::string, std::shared_ptr<Employee>> employees = m_dataStore.getEmployees();
auto employeeIterator = employees.find(id);
if (employeeIterator == employees.end())
{
return false;
}
auto generalEmployee = std::dynamic_pointer_cast<GeneralEmployee>((*employeeIterator).second);
if (generalEmployee)
{
generalEmployee->setDesignation(designation);
}
return true;
}
std::shared_ptr<const Employee> EmployeeManagementService::getCurrentEmployee()
{
return m_dataStore.getAuthenticatedEmployee();
@@ -17,6 +17,7 @@ public:
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
bool deactivateEmployee(const std::string&);
bool updateDesignation(const std::string&,Enums::EmployeeDesignation);
void updateProfile(const std::string&,const std::string&);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
std::shared_ptr<const Employee> getCurrentEmployee();
@@ -13,7 +13,7 @@ void AdminMenu::run()
{
int choice;
util::clear();
std::cout << "Admin Menu\n1. Create User\n2. View Employees\n3. Deactivate Employee\n4. Search Employee\n5. Update Profile\n6. Logout\nEnter your Choice: ";
std::cout << "Admin Menu\n1. Create User\n2. View Employees\n3. Deactivate Employee\n4. Search Employee\n5. Update Profile\n6. Update Designation \n7. Logout\nEnter your Choice: ";
util::read(choice);
if (!handleOperation(choice))
{
@@ -48,6 +48,9 @@ bool AdminMenu::handleOperation(int choice)
updateProfile(m_zenvyController);
break;
case 6:
updateDesignation(m_zenvyController);
break;
case 7:
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
@@ -13,7 +13,7 @@ void HRManagerMenu::run()
{
int choice;
util::clear();
std::cout << "HR Manager Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create Employee\n9. Regularize Attendance\n10. Update Leave Request\n11. Register CandidateAsEmployee\n12. Update Profile\n13. Deactivate Employee\n14. View Profile\n15. Logout\nEnter your Choice: ";
std::cout << "HR Manager Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create Employee\n9. Regularize Attendance\n10. Update Leave Request\n11. Register CandidateAsEmployee\n12. Update Profile\n13. Deactivate Employee\n14. View Profile\n15. Update Designation\n16. Logout\nEnter your Choice: ";
util::read(choice);
if (!handleOperation(choice))
{
@@ -51,6 +51,9 @@ bool HRManagerMenu::handleOperation(int choice)
viewProfile(m_zenvyController);
break;
case 15:
updateDesignation(m_zenvyController);
break;
case 16:
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
@@ -102,3 +102,23 @@ void createEmployee(std::shared_ptr<ZenvyController> controller)
std::cout << "\nCreated Employee Successfully.";
util::pressEnter();
}
void updateDesignation(std::shared_ptr<ZenvyController> m_zenvyController)
{
std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees(Enums::EmployeeType::GENERAL));
if (selectedEmployeeId.empty())
{
return;
}
Enums::EmployeeDesignation designation = getEmployeeDesignation();
if (m_zenvyController->updateDesignation(selectedEmployeeId, designation))
{
std::cout << "Assigned Employee Role Successfully\n";
util::pressEnter();
}
else
{
std::cout << "Employee not found\n";
util::pressEnter();
}
}
+19 -4
View File
@@ -14,6 +14,7 @@
#include "Validator.h"
void createEmployee(std::shared_ptr<ZenvyController> controller);
void updateDesignation(std::shared_ptr<ZenvyController> m_zenvyController);
inline void viewProfile(std::shared_ptr<ZenvyController> controller)
{
@@ -134,15 +135,29 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
<< std::setw(10) << "Index"
<< std::setw(15) << "Employee ID"
<< std::setw(20) << "Name"
<< std::setw(20) << "Employee Type" << std::endl;
<< std::setw(20) << "Employee Type"
<< std::setw(20) << "Employee Designation" << std::endl;
for (const auto& employee : employeeList)
{
std::cout << std::left << std::setw(10) << employee.first
auto generalEmployee = std::dynamic_pointer_cast<const GeneralEmployee>(employee.second);
std::cout << std::left
<< std::setw(10) << employee.first
<< std::setw(15) << employee.second->getId()
<< std::setw(20) << employee.second->getEmployeeName()
<< std::setw(20) << Enums::getEmployeeTypeString(employee.second->getEmployeeType())
<< std::setw(20) << Enums::getEmployeeTypeString(employee.second->getEmployeeType());
if (generalEmployee)
{
std::cout << std::left
<< std::setw(20) << Enums::getEmployeeDesignationString(generalEmployee->getDesignation())
<< std::endl;
}
else
{
std::cout << std::left
<< std::setw(20) << "NULL"
<< std::endl;
}
}
std::cout << "Enter the Index: ";
util::read(choice);
auto employeeIterator = employeeList.find(choice);
@@ -163,7 +178,7 @@ inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controlle
{
return;
}
if(controller->deactivateEmployee(selectedEmployeeId))
if (controller->deactivateEmployee(selectedEmployeeId))
{
std::cout << "Employee deactivated successfully\n";
util::pressEnter();