Files
Training-Team2-Zenvy-Jan26/Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.cpp
T
joelthomastrenser aa21853a65 Refactored employee selection and cleaned up menu logic
<SRS> SRS02 : Employee Management </SRS>

<Changes>
 - Removed getSelectedUserId() from FinanceExecutiveMenu
 - Added reusable selectEmployeeId() in MenuHelper
 - Simplified deactivateEmployee() using common selection logic
 - Fixed missing break in HRManagerMenu
</Changes>

<Review>
Smitha Mohan
</Review>
2026-04-11 14:59:41 +05:30

105 lines
3.4 KiB
C++

#include <stdexcept>
#include "MenuHelper.h"
static Enums::EmployeeType getEmployeeType(Enums::EmployeeType employeeType)
{
int choice;
util::clear();
static const std::map<Enums::EmployeeType, std::vector<Enums::EmployeeType>> employeeTypeOptions = {
{ Enums::EmployeeType::ADMIN, {
Enums::EmployeeType::HR,
Enums::EmployeeType::IT,
Enums::EmployeeType::TEAM,
Enums::EmployeeType::FINANCE,
Enums::EmployeeType::TALENT_ACQUISITION,
Enums::EmployeeType::GENERAL
}},
{ Enums::EmployeeType::HR, {
Enums::EmployeeType::IT,
Enums::EmployeeType::TEAM,
Enums::EmployeeType::FINANCE,
Enums::EmployeeType::TALENT_ACQUISITION,
Enums::EmployeeType::GENERAL
}}
};
static const std::map<Enums::EmployeeType, std::string> labels = {
{ Enums::EmployeeType::HR, "HR Employee" },
{ Enums::EmployeeType::IT, "IT Executive" },
{ Enums::EmployeeType::TEAM, "Team Executive" },
{ Enums::EmployeeType::FINANCE, "Finance Executive" },
{ Enums::EmployeeType::TALENT_ACQUISITION, "Talent Executive" },
{ Enums::EmployeeType::GENERAL, "General Employee" }
};
auto it = employeeTypeOptions.find(employeeType);
if (it == employeeTypeOptions.end())
{
throw std::runtime_error("You do not have the authority to create a new Employee!");
}
const auto& options = it->second;
std::cout << "Select Employee Type\n";
for (int index = 0; index < options.size(); ++index)
{
std::cout << index + 1 << ". " << labels.at(options[index]) << "\n";
}
std::cout << "Enter Choice: ";
util::read(choice);
if (choice >= 1 && choice <= options.size())
{
return options[choice - 1];
}
return Enums::EmployeeType::INVALID;
}
static Enums::EmployeeDesignation getEmployeeDesignation()
{
int choice;
util::clear();
std::cout << "Select Employee Designation"
"\n1. SENIOR"
"\n2. JUNIOR"
"\nEnter Choice: ";
util::read(choice);
switch (choice)
{
case 1:
return Enums::EmployeeDesignation::SENIOR;
case 2:
return Enums::EmployeeDesignation::JUNIOR;
default:
return Enums::EmployeeDesignation::INVALID;
}
}
void createEmployee(std::shared_ptr<ZenvyController> controller)
{
auto currentEmployee = controller->getCurrentEmployee();
Enums::EmployeeType employeeType = getEmployeeType(currentEmployee->getEmployeeType());
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
std::string name, email, phone;
switch (employeeType)
{
case Enums::EmployeeType::INVALID:
std::cout << "Invalid Choice";
util::pressEnter();
return;
case Enums::EmployeeType::GENERAL:
employeeDesignation = getEmployeeDesignation();
if (employeeDesignation == Enums::EmployeeDesignation::INVALID)
{
std::cout << "Invalid Choice";
util::pressEnter();
return;
}
break;
}
std::cout << "Enter Name: ";
util::read(name);
std::cout << "Enter Email: ";
util::read(email);
std::cout << "Enter Phone: ";
util::read(phone);
controller->createEmployee(employeeType, employeeDesignation, email, name, phone);
std::cout << "\nCreated Employee Successfully.";
util::pressEnter();
}