Add Update Designation functionality for General Employees

<UserStory> EMP005 : Update Designation </UserStory>

<Changes>
 - Added updateDesignation method in ZenvyController and EmployeeManagementService.
 - Implemented update designation logic with authorization checks.
 - Enabled Admin menu option to update employee designation
 - Display employee designation in employee selection list
 - Extended GeneralEmployee to expose and update designation
 - Integrated role selection flow in MenuHelper.
</Changes>

<Review>
  Smitha Mohan
</Review>
This commit is contained in:
Tinu Johnson
2026-04-14 15:09:46 +05:30
committed by Joel Thomas
parent a8ca6be135
commit 5398f5a0ee
9 changed files with 102 additions and 33 deletions
@@ -42,6 +42,11 @@ std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
return m_employeeManagementService->getCurrentEmployee(); return m_employeeManagementService->getCurrentEmployee();
} }
bool ZenvyController::updateDesignation(const std::string& id,Enums::EmployeeDesignation designation)
{
return m_employeeManagementService->updateDesignation(id,designation);
}
//Payslip Management //Payslip Management
void ZenvyController::updateSalary(const std::string& employeeId, double basicSalary, double houseRentAllowance, double foodAllowance, double employeePFContribution, double employerPFContribution) 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(); std::shared_ptr<const Employee> getCurrentEmployee();
void updateProfile(const std::string&,const std::string&); void updateProfile(const std::string&,const std::string&);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(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> template <typename ...Types>
Employees getEmployees(Types ...types) Employees getEmployees(Types ...types)
{ {
@@ -2,7 +2,7 @@
#include "GeneralEmployee.h" #include "GeneralEmployee.h"
#include "Factory.h" #include "Factory.h"
Enums::EmployeeDesignation GeneralEmployee::getDesignation() const Enums::EmployeeDesignation GeneralEmployee::getDesignation() const
{ {
return m_designation; return m_designation;
} }
@@ -8,7 +8,8 @@ private:
Enums::EmployeeDesignation m_designation; Enums::EmployeeDesignation m_designation;
public: public:
GeneralEmployee() GeneralEmployee()
: m_designation(Enums::EmployeeDesignation::JUNIOR) {} : m_designation(Enums::EmployeeDesignation::JUNIOR) {
}
GeneralEmployee(const std::string& name, GeneralEmployee(const std::string& name,
const std::string& phone, const std::string& phone,
const std::string& email, const std::string& email,
@@ -19,7 +20,8 @@ public:
email, email,
Enums::EmployeeType::GENERAL, Enums::EmployeeType::GENERAL,
payroll), payroll),
m_designation(designation) {} m_designation(designation) {
}
GeneralEmployee(const std::string& id, GeneralEmployee(const std::string& id,
const std::string& name, const std::string& name,
const std::string& phone, const std::string& phone,
@@ -38,7 +40,8 @@ public:
teamStatus, teamStatus,
Enums::EmployeeType::GENERAL, Enums::EmployeeType::GENERAL,
accountStatus), accountStatus),
m_designation(employeeDesignation) {} m_designation(employeeDesignation) {
}
Enums::EmployeeDesignation getDesignation() const; Enums::EmployeeDesignation getDesignation() const;
void setDesignation(Enums::EmployeeDesignation designation); void setDesignation(Enums::EmployeeDesignation designation);
std::string serialize() const override; std::string serialize() const override;
@@ -131,6 +131,24 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
return true; 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>> employee = m_dataStore.getEmployees();
auto iterator = employee.find(id);
if (iterator == employee.end())
{
return false;
}
auto generalEmployee = std::dynamic_pointer_cast<GeneralEmployee>((*iterator).second);
if (generalEmployee)
{
generalEmployee->setDesignation(designation);
}
return true;
}
std::shared_ptr<const Employee> EmployeeManagementService::getCurrentEmployee() std::shared_ptr<const Employee> EmployeeManagementService::getCurrentEmployee()
{ {
return m_dataStore.getAuthenticatedEmployee(); return m_dataStore.getAuthenticatedEmployee();
@@ -17,6 +17,7 @@ public:
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {}; EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&); void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
bool deactivateEmployee(const std::string&); bool deactivateEmployee(const std::string&);
bool updateDesignation(const std::string&,Enums::EmployeeDesignation);
void updateProfile(const std::string&,const std::string&); void updateProfile(const std::string&,const std::string&);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&); std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
std::shared_ptr<const Employee> getCurrentEmployee(); std::shared_ptr<const Employee> getCurrentEmployee();
@@ -13,7 +13,7 @@ void AdminMenu::run()
{ {
int choice; int choice;
util::clear(); 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); util::read(choice);
if (!handleOperation(choice)) if (!handleOperation(choice))
{ {
@@ -48,6 +48,9 @@ bool AdminMenu::handleOperation(int choice)
updateProfile(m_zenvyController); updateProfile(m_zenvyController);
break; break;
case 6: case 6:
updateDesignation(m_zenvyController);
break;
case 7:
return false; return false;
default: default:
std::cout << "Enter a valid choice!" << std::endl; std::cout << "Enter a valid choice!" << std::endl;
@@ -102,3 +102,23 @@ void createEmployee(std::shared_ptr<ZenvyController> controller)
std::cout << "\nCreated Employee Successfully."; std::cout << "\nCreated Employee Successfully.";
util::pressEnter(); 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 << "Assign Employee Role successfull\n";
util::pressEnter();
}
else
{
std::cout << "Employee not found\n";
util::pressEnter();
}
}
+46 -27
View File
@@ -14,6 +14,7 @@
#include "Validator.h" #include "Validator.h"
void createEmployee(std::shared_ptr<ZenvyController> controller); void createEmployee(std::shared_ptr<ZenvyController> controller);
void updateDesignation(std::shared_ptr<ZenvyController> m_zenvyController);
inline void viewProfile(std::shared_ptr<ZenvyController> controller) inline void viewProfile(std::shared_ptr<ZenvyController> controller)
{ {
@@ -134,14 +135,31 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
<< std::setw(10) << "Index" << std::setw(10) << "Index"
<< std::setw(15) << "Employee ID" << std::setw(15) << "Employee ID"
<< std::setw(20) << "Name" << 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) 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::setw(15) << employee.second->getId() if (generalEmployee)
<< std::setw(20) << employee.second->getEmployeeName() {
<< std::setw(20) << Enums::getEmployeeTypeString(employee.second->getEmployeeType()) std::cout << std::left
<< std::endl; << std::setw(10) << employee.first
<< std::setw(15) << generalEmployee->getId()
<< std::setw(20) << generalEmployee->getEmployeeName()
<< std::setw(20) << Enums::getEmployeeTypeString(generalEmployee->getEmployeeType())
<< std::setw(20) << Enums::getEmployeeDesignationString(generalEmployee->getDesignation())
<< std::endl;
}
else
{
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) << "NULL"
<< std::endl;
}
} }
std::cout << "Enter the Index: "; std::cout << "Enter the Index: ";
util::read(choice); util::read(choice);
@@ -163,7 +181,7 @@ inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controlle
{ {
return; return;
} }
if(controller->deactivateEmployee(selectedEmployeeId)) if (controller->deactivateEmployee(selectedEmployeeId))
{ {
std::cout << "Employee deactivated successfully\n"; std::cout << "Employee deactivated successfully\n";
util::pressEnter(); util::pressEnter();
@@ -210,13 +228,13 @@ inline void viewEmployees(std::shared_ptr<ZenvyController> m_zenvyController)
inline void searchEmployee(std::shared_ptr<ZenvyController>& m_zenvyController) inline void searchEmployee(std::shared_ptr<ZenvyController>& m_zenvyController)
{ {
std::string name; std::string name;
util::clear(); util::clear();
std::cout << "Enter Employee Name: "; std::cout << "Enter Employee Name: ";
util::read(name); util::read(name);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchResults = m_zenvyController->searchEmployee(name); std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchResults = m_zenvyController->searchEmployee(name);
if (!(searchResults.second).empty()) if (!(searchResults.second).empty())
{ {
std::cout << std::left std::cout << std::left
<< std::setw(10) << "ID" << std::setw(10) << "ID"
<< std::setw(20) << "Name" << std::setw(20) << "Name"
@@ -238,10 +256,10 @@ inline void searchEmployee(std::shared_ptr<ZenvyController>& m_zenvyController)
<< std::setw(15) << "HouseRentAllowance"; << std::setw(15) << "HouseRentAllowance";
} }
std::cout << std::endl; std::cout << std::endl;
for (const auto& employee : searchResults.second) for (const auto& employee : searchResults.second)
{ {
if (employee->getEmployeeAccountStatus() == Enums::AccountStatus::ACTIVE) if (employee->getEmployeeAccountStatus() == Enums::AccountStatus::ACTIVE)
{ {
std::cout << std::left std::cout << std::left
<< std::setw(10) << employee->getId() << std::setw(10) << employee->getId()
<< std::setw(20) << employee->getEmployeeName() << std::setw(20) << employee->getEmployeeName()
@@ -257,8 +275,8 @@ inline void searchEmployee(std::shared_ptr<ZenvyController>& m_zenvyController)
{ {
std::cout << std::setw(15) << employee->getEmployeeTeamId(); std::cout << std::setw(15) << employee->getEmployeeTeamId();
} }
if (searchResults.first == Enums::EmployeeType::FINANCE if (searchResults.first == Enums::EmployeeType::FINANCE
|| searchResults.first == Enums::EmployeeType::HR || searchResults.first == Enums::EmployeeType::HR
|| searchResults.first == Enums::EmployeeType::ADMIN) || searchResults.first == Enums::EmployeeType::ADMIN)
{ {
std::cout << std::left std::cout << std::left
@@ -270,12 +288,13 @@ inline void searchEmployee(std::shared_ptr<ZenvyController>& m_zenvyController)
<< std::setw(15) << employee->getPayroll()->getHouseRentAllowance(); << std::setw(15) << employee->getPayroll()->getHouseRentAllowance();
} }
std::cout << std::endl; std::cout << std::endl;
} }
} }
} }
else else
{ {
std::cout << "No Employee found with this name" << std::endl; std::cout << "No Employee found with this name" << std::endl;
} }
util::pressEnter(); util::pressEnter();
} }