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:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,8 @@ private:
|
||||
Enums::EmployeeDesignation m_designation;
|
||||
public:
|
||||
GeneralEmployee()
|
||||
: m_designation(Enums::EmployeeDesignation::JUNIOR) {}
|
||||
: m_designation(Enums::EmployeeDesignation::JUNIOR) {
|
||||
}
|
||||
GeneralEmployee(const std::string& name,
|
||||
const std::string& phone,
|
||||
const std::string& email,
|
||||
@@ -19,7 +20,8 @@ public:
|
||||
email,
|
||||
Enums::EmployeeType::GENERAL,
|
||||
payroll),
|
||||
m_designation(designation) {}
|
||||
m_designation(designation) {
|
||||
}
|
||||
GeneralEmployee(const std::string& id,
|
||||
const std::string& name,
|
||||
const std::string& phone,
|
||||
@@ -38,7 +40,8 @@ public:
|
||||
teamStatus,
|
||||
Enums::EmployeeType::GENERAL,
|
||||
accountStatus),
|
||||
m_designation(employeeDesignation) {}
|
||||
m_designation(employeeDesignation) {
|
||||
}
|
||||
Enums::EmployeeDesignation getDesignation() const;
|
||||
void setDesignation(Enums::EmployeeDesignation designation);
|
||||
std::string serialize() const override;
|
||||
|
||||
@@ -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>> 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()
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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 << "Assign Employee Role successfull\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Employee not found\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
@@ -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,32 @@ 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);
|
||||
if (generalEmployee)
|
||||
{
|
||||
std::cout << std::left
|
||||
<< 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: ";
|
||||
util::read(choice);
|
||||
auto employeeIterator = employeeList.find(choice);
|
||||
@@ -163,7 +181,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();
|
||||
@@ -279,3 +297,4 @@ inline void searchEmployee(std::shared_ptr<ZenvyController>& m_zenvyController)
|
||||
}
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user