f15d5b7f1d
<UserStory> EMP012 : Add Shorlisted Candidates As Employee </UserStory> <Changes> - Added clear method to clear console before displaying candidate details in MenuHelper.cpp - Removed spaces in MenuHelper.h </Changes> <Review> Smitha Mohan </Review>
203 lines
6.9 KiB
C++
203 lines
6.9 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 employeeOptionsIterator = employeeTypeOptions.find(employeeType);
|
|
if (employeeOptionsIterator == employeeTypeOptions.end())
|
|
{
|
|
throw std::runtime_error("You do not have the authority to create a new Employee!");
|
|
}
|
|
const auto& options = employeeOptionsIterator->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();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
void displayCandidateDetails(const std::vector<std::shared_ptr<Candidate>>& shorlistedCandidates)
|
|
{
|
|
util::clear();
|
|
std::cout << std::left
|
|
<< std::setw(10) << "Index"
|
|
<< std::setw(10) << "ID"
|
|
<< std::setw(20) << "Name"
|
|
<< std::setw(15) << "Phone"
|
|
<< std::setw(15) << "Qualification"
|
|
<< std::setw(10) << "Status"
|
|
<< std::endl;
|
|
int index = 0;
|
|
for (auto& candidate : shorlistedCandidates)
|
|
{
|
|
std::cout << std::left
|
|
<< std::setw(10) << ++index
|
|
<< std::setw(10) << candidate->getCandidateId()
|
|
<< std::setw(20) << candidate->getCandidateName()
|
|
<< std::setw(15) << candidate->getCandidatePhone()
|
|
<< std::setw(15) << candidate->getCandidateQualification()
|
|
<< std::setw(10) << Enums::getCandidateStatusString(candidate->getCandidateStatus())
|
|
<< std::endl;
|
|
}
|
|
}
|
|
|
|
void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& controller)
|
|
{
|
|
int index;
|
|
std::string name, email, phone;
|
|
util::clear();
|
|
std::vector<std::shared_ptr<Candidate>> shortlistedCandidates = controller->getShorlistedCandidates();
|
|
if (shortlistedCandidates.empty())
|
|
{
|
|
std::cout << "No candidates Found!";
|
|
util::pressEnter();
|
|
return;
|
|
}
|
|
displayCandidateDetails(shortlistedCandidates);
|
|
std::cout << "Enter the Index: ";
|
|
util::read(index);
|
|
auto currentEmployee = controller->getCurrentEmployee();
|
|
Enums::EmployeeType employeeType;
|
|
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
|
|
if (index > 0 && index < shortlistedCandidates.size())
|
|
{
|
|
employeeType = getEmployeeType(currentEmployee->getEmployeeType());
|
|
std::shared_ptr<Candidate> candidate = shortlistedCandidates[index - 1];
|
|
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 email: ";
|
|
util::read(email);
|
|
name = candidate->getCandidateName();
|
|
phone = candidate->getCandidatePhone();
|
|
controller->createEmployee(employeeType, employeeDesignation, email, name, phone);
|
|
candidate->setCandidateStatus(Enums::CandidateStatus::HIRED);
|
|
std::cout << "\nCreated Employee Successfully.";
|
|
util::pressEnter();
|
|
}
|
|
else
|
|
{
|
|
throw std::runtime_error("Enter a valid Index.");
|
|
}
|
|
}
|