Implement employee creation

<UserStory>EMP001 Create Employee</UserStory>

<Changes>
- Updated employee creation flow to support different employee types and designations
- Set a default initial password for new employees
- Added basic authorization check utility
- Cleaned up employee model constructors for better consistency
Minor code cleanup and refactoring
</Changes>

<Review>
Smitha Mohan
</Review>
This commit is contained in:
2026-04-07 15:07:44 +05:30
parent 07bd979685
commit ef5ac42a92
19 changed files with 318 additions and 56 deletions
@@ -162,6 +162,7 @@
<ClCompile Include="models\Employee.cpp" />
<ClCompile Include="models\HRManager.cpp" />
<ClCompile Include="Trenser.Zenvy.cpp" />
<ClCompile Include="utilities\AuthorizationHelper.cpp" />
<ClCompile Include="utilities\Enums.cpp" />
<ClCompile Include="utilities\InputHelper.cpp" />
<ClCompile Include="utilities\OutputHelper.cpp" />
@@ -212,6 +213,7 @@
<ClInclude Include="services\TalentAcquisitionManagementService.h" />
<ClInclude Include="services\TeamManagementService.h" />
<ClInclude Include="services\TicketManagementService.h" />
<ClInclude Include="utilities\AuthorizationHelper.h" />
<ClInclude Include="utilities\Enums.h" />
<ClInclude Include="utilities\InputHelper.h" />
<ClInclude Include="utilities\OutputHelper.h" />
@@ -17,9 +17,9 @@ void ZenvyController::changePassword(const std::string& password)
}
//Employee Management
void ZenvyController::createEmployee(Enums::EmployeeType employeeType, const std::string& email, const std::string& password, const std::string& name, const std::string& phone)
void ZenvyController::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
{
m_employeeManagementService->createEmployee(employeeType, email, password, name, phone);
m_employeeManagementService->createEmployee(employeeType, employeeDesignation, email, name, phone);
}
bool ZenvyController::deactivateEmployee(const std::string& id)
@@ -45,7 +45,7 @@ public:
void changePassword(const std::string&);
//Employee Management
void createEmployee(Enums::EmployeeType, const std::string&, 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&);
Employees getEmployees();
std::shared_ptr<const Employee> getEmployee(const std::string&);
+2 -4
View File
@@ -3,15 +3,13 @@
class Admin : public Employee
{
public:
Admin() = default;
Admin(
const std::string& password,
const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
std::shared_ptr<Payroll> payroll
) :Employee(password, name, phone, email, teamId, Enums::EmployeeType::GENERAL, payroll) {
};
) :Employee(name, phone, email, Enums::EmployeeType::GENERAL, payroll) {};
~Admin() = default;
};
@@ -7,6 +7,7 @@
#include "Leave.h"
#include "Payroll.h"
#include "Enums.h"
#include "ApplicationConfig.h"
using payslipMap = std::map<std::string, std::shared_ptr<Payslip>>;
using attendanceMap = std::map<int, std::map<std::string, std::shared_ptr<Attendance>>>;
using leaveMap = std::map<std::string, std::shared_ptr<Leave>>;
@@ -29,15 +30,13 @@ private:
leaveMap m_leaves;
Enums::EmployeeType m_employeeType;
public:
Employee() : m_id("EMP" + std::to_string(++m_uid)), m_password(""), m_name(""), m_phone(""), m_email(""), m_accountStatus(Enums::AccountStatus::ACTIVE), m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM), m_teamId(""), m_employeeType(Enums::EmployeeType::GENERAL) {}
Employee(const std::string& password,
const std::string& name,
Employee() : m_id("EMP" + std::to_string(++m_uid)), m_password(Config::Authentication::DEFAULT_PASSWORD), m_name(""), m_phone(""), m_email(""), m_accountStatus(Enums::AccountStatus::ACTIVE), m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM), m_teamId(""), m_employeeType(Enums::EmployeeType::GENERAL) {}
Employee(const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
Enums::EmployeeType employeeType,
std::shared_ptr<Payroll> payroll)
: m_id("EMP" + std::to_string(++m_uid)), m_password(password), m_name(name), m_phone(phone), m_email(email), m_accountStatus(Enums::AccountStatus::ACTIVE), m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM), m_teamId(teamId), m_employeeType(employeeType), m_payroll(payroll) { }
: m_id("EMP" + std::to_string(++m_uid)), m_password(Config::Authentication::DEFAULT_PASSWORD), m_name(name), m_phone(phone), m_email(email), m_accountStatus(Enums::AccountStatus::ACTIVE), m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM), m_teamId(""), m_employeeType(employeeType), m_payroll(payroll) { }
const std::string& getEmployeeId() const;
const std::string& getEmployeePassword() const;
const std::string& getEmployeeName() const;
@@ -7,13 +7,11 @@ class FinanceExecutive : public Employee
public:
FinanceExecutive() = default;
FinanceExecutive(
const std::string& password,
const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
std::shared_ptr<Payroll> payroll
) :Employee(password, name, phone, email, teamId, Enums::EmployeeType::GENERAL, payroll) {};
) :Employee(name, phone, email, Enums::EmployeeType::FINANCE, payroll) {};
~FinanceExecutive() = default;
};
@@ -8,14 +8,11 @@ private:
Enums::EmployeeDesignation m_designation;
public:
GeneralEmployee() : m_designation(Enums::EmployeeDesignation::JUNIOR) {}
GeneralEmployee(const std::string& id,
const std::string& password,
const std::string& name,
GeneralEmployee(const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
std::shared_ptr<Payroll> payroll,
Enums::EmployeeDesignation designation) : Employee(password, name, phone, email, teamId,Enums::EmployeeType::GENERAL, payroll), m_designation(designation) {}
Enums::EmployeeDesignation designation) : Employee(name, phone, email, Enums::EmployeeType::GENERAL, payroll), m_designation(designation) {}
Enums::EmployeeDesignation getDesignation() const;
void setDesignation(Enums::EmployeeDesignation designation);
~GeneralEmployee() = default;
@@ -3,16 +3,14 @@
class HRManager : public Employee
{
public:
HRManager() = default;
HRManager(
const std::string& password,
const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
std::shared_ptr<Payroll> payroll
) :Employee(password, name, phone, email, teamId, Enums::EmployeeType::GENERAL, payroll) {
};
) :Employee(name, phone, email, Enums::EmployeeType::HR, payroll) {};
~HRManager() = default;
};
@@ -3,16 +3,14 @@
class ITExecutive : public Employee
{
public:
ITExecutive() = default;
ITExecutive(
const std::string& password,
const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
std::shared_ptr<Payroll> payroll
) :Employee(password, name, phone, email, teamId, Enums::EmployeeType::GENERAL, payroll) {
};
) :Employee(name, phone, email, Enums::EmployeeType::GENERAL, payroll) {};
~ITExecutive() = default;
};
@@ -3,16 +3,14 @@
class TalentExecutive : public Employee
{
public:
TalentExecutive() = default;
TalentExecutive(
const std::string& password,
const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
std::shared_ptr<Payroll> payroll
) :Employee(password, name, phone, email, teamId, Enums::EmployeeType::GENERAL, payroll) {
};
) :Employee(name, phone, email, Enums::EmployeeType::TAG, payroll) {};
~TalentExecutive() = default;
};
@@ -3,16 +3,14 @@
class TeamExecutive : public Employee
{
public:
TeamExecutive() = default;
TeamExecutive(
const std::string& password,
const std::string& name,
const std::string& phone,
const std::string& email,
const std::string& teamId,
std::shared_ptr<Payroll> payroll
) :Employee(password, name, phone, email, teamId, Enums::EmployeeType::GENERAL, payroll) {
};
) :Employee(name, phone, email, Enums::EmployeeType::TEAM, payroll) {};
~TeamExecutive() = default;
};
@@ -9,11 +9,6 @@ namespace Config
namespace Payroll
{
constexpr double TEAM_LEAD_BASIC_SALARY = 0.0;
constexpr double TEAM_LEAD_HOUSE_RENT_ALLOWANCE = 0.0;
constexpr double TEAM_LEAD_FOOD_ALLOWANCE = 0.0;
constexpr double TEAM_LEAD_EMPLOYEE_PF_CONTRIBUTION = 0.0;
constexpr double TEAM_LEAD_EMPLOYER_PF_CONTRIBUTION = 0.0;
constexpr double SENIOR_BASIC_SALARY = 0.0;
constexpr double SENIOR_HOUSE_RENT_ALLOWANCE = 0.0;
constexpr double SENIOR_FOOD_ALLOWANCE = 0.0;
@@ -1,7 +1,99 @@
#include <stdexcept>
#include "EmployeeManagementService.h"
#include "Factory.h"
#include "Validator.h"
#include "AuthorizationHelper.h"
#include "Enums.h"
#include "HRManager.h"
#include "ITExecutive.h"
#include "TalentExecutive.h"
#include "TeamExecutive.h"
#include "FinanceExecutive.h"
#include "GeneralEmployee.h"
void EmployeeManagementService::createEmployee(Enums::EmployeeType, const std::string& email, const std::string& password, const std::string& name, const std::string& phone)
void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
{
std::shared_ptr<Employee> authenticatedEmployee = m_dataStore.getAuthenticatedEmployee();
if (!authenticatedEmployee)
{
throw std::runtime_error("No authenticated user");
}
Enums::EmployeeType authenticatedEmployeeType = authenticatedEmployee->getEmployeeType();
std::shared_ptr<Employee> employee;
std::shared_ptr<Payroll> payroll;
if (!util::isEmailValid(email))
{
throw std::runtime_error("Invalid Email");
}
if (!util::isPhoneNumberValid(phone))
{
throw std::runtime_error("Invalid Phone");
}
switch (employeeType)
{
case Enums::EmployeeType::HR:
util::enforceAuthorization(authenticatedEmployeeType, Enums::EmployeeType::ADMIN);
payroll = Factory::getObject<Payroll>(Config::Payroll::HR_MANAGER_BASIC_SALARY,
Config::Payroll::HR_MANAGER_HOUSE_RENT_ALLOWANCE,
Config::Payroll::HR_MANAGER_FOOD_ALLOWANCE,
Config::Payroll::HR_MANAGER_EMPLOYEE_PF_CONTRIBUTION,
Config::Payroll::HR_MANAGER_EMPLOYER_PF_CONTRIBUTION);
employee = Factory::getObject<HRManager>(name, phone, email, payroll);
break;
case Enums::EmployeeType::IT:
case Enums::EmployeeType::FINANCE:
case Enums::EmployeeType::TEAM:
case Enums::EmployeeType::TAG:
util::enforceAuthorization(authenticatedEmployeeType, Enums::EmployeeType::ADMIN, Enums::EmployeeType::HR);
payroll = Factory::getObject<Payroll>(Config::Payroll::EXECUTIVE_BASIC_SALARY,
Config::Payroll::EXECUTIVE_HOUSE_RENT_ALLOWANCE,
Config::Payroll::EXECUTIVE_FOOD_ALLOWANCE,
Config::Payroll::EXECUTIVE_EMPLOYEE_PF_CONTRIBUTION,
Config::Payroll::EXECUTIVE_EMPLOYER_PF_CONTRIBUTION);
switch (employeeType)
{
case Enums::EmployeeType::IT:
employee = Factory::getObject<ITExecutive>(name, phone, email, payroll);
break;
case Enums::EmployeeType::FINANCE:
employee = Factory::getObject<FinanceExecutive>(name, phone, email, payroll);
break;
case Enums::EmployeeType::TEAM:
employee = Factory::getObject<TeamExecutive>(name, phone, email, payroll);
break;
case Enums::EmployeeType::TAG:
employee = Factory::getObject <TalentExecutive> (name, phone, email, payroll);
break;
}
break;
case Enums::EmployeeType::GENERAL:
util::enforceAuthorization(authenticatedEmployeeType, Enums::EmployeeType::ADMIN, Enums::EmployeeType::HR);
switch (employeeDesignation)
{
case Enums::EmployeeDesignation::JUNIOR:
payroll = Factory::getObject<Payroll>(Config::Payroll::JUNIOR_BASIC_SALARY,
Config::Payroll::JUNIOR_HOUSE_RENT_ALLOWANCE,
Config::Payroll::JUNIOR_FOOD_ALLOWANCE,
Config::Payroll::JUNIOR_EMPLOYEE_PF_CONTRIBUTION,
Config::Payroll::JUNIOR_EMPLOYER_PF_CONTRIBUTION);
break;
case Enums::EmployeeDesignation::SENIOR:
payroll = Factory::getObject<Payroll>(Config::Payroll::SENIOR_BASIC_SALARY,
Config::Payroll::SENIOR_HOUSE_RENT_ALLOWANCE,
Config::Payroll::SENIOR_FOOD_ALLOWANCE,
Config::Payroll::SENIOR_EMPLOYEE_PF_CONTRIBUTION,
Config::Payroll::SENIOR_EMPLOYER_PF_CONTRIBUTION);
break;
default:
throw std::runtime_error("Invalid General Employee Designation");
}
employee = Factory::getObject<GeneralEmployee>(name, phone, email, payroll, employeeDesignation);
break;
default:
throw std::runtime_error("Invalid Employee Type");
}
m_dataStore.getEmployees().emplace(std::make_pair(employee->getEmployeeId(), employee));
}
bool EmployeeManagementService::deactivateEmployee(const std::string& id)
@@ -12,7 +12,7 @@ private:
DataStore& m_dataStore;
public:
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
void createEmployee(Enums::EmployeeType, const std::string&, 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&);
Employees getEmployees();
std::shared_ptr<const Employee> getEmployee(const std::string&);
@@ -1,4 +1,5 @@
#pragma once
#include "DataStore.h"
class PayslipManagementService
{
@@ -0,0 +1 @@
#include "AuthorizationHelper.h"
@@ -0,0 +1,31 @@
#pragma once
#include <stdexcept>
#include "Enums.h"
namespace util
{
inline bool isAuthorized(Enums::EmployeeType current, Enums::EmployeeType first)
{
return current == first;
}
template <typename... Rest>
inline bool isAuthorized(Enums::EmployeeType current, Enums::EmployeeType first,
Rest... rest)
{
if (current == first)
{
return true;
}
return isAuthorized(current, rest...);
}
template <typename... Allowed>
inline void enforceAuthorization(Enums::EmployeeType current, Allowed... allowed)
{
if (!isAuthorized(current, allowed...))
{
throw std::runtime_error("You are unauthorized to perform this operation!");
}
}
}
+88 -10
View File
@@ -3,6 +3,87 @@
#include"InputHelper.h"
#include"OutputHelper.h"
static Enums::EmployeeType getEmployeeType()
{
int choice;
util::clear();
std::cout << "Select Employee Type"
"\n1. HR Employee"
"\n2. IT Executive"
"\n3. Team Executive"
"\n4. Finance Executive"
"\n5. Talent Executive"
"\n6. General Employee";
util::read(choice);
switch (choice)
{
case 1:
return Enums::EmployeeType::HR;
case 2:
return Enums::EmployeeType::IT;
case 3:
return Enums::EmployeeType::TEAM;
case 4:
return Enums::EmployeeType::FINANCE;
case 5:
return Enums::EmployeeType::TAG;
case 6:
return Enums::EmployeeType::GENERAL;
default:
return Enums::EmployeeType::INVALID;
}
}
static Enums::EmployeeDesignation getEmployeeDesignation()
{
int choice;
util::clear();
std::cout << "Select Employee Designation"
"\n1. SENIOR"
"\n2. JUNIOR";
util::read(choice);
switch (choice)
{
case 1:
return Enums::EmployeeDesignation::SENIOR;
case 2:
return Enums::EmployeeDesignation::JUNIOR;
default:
return Enums::EmployeeDesignation::INVALID;
}
}
static void createEmployee(std::shared_ptr<ZenvyController> controller)
{
Enums::EmployeeType employeeType = 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, name, email, phone);
std::cout << "\nCreated Employee Successfully.";
}
void AdminMenu::run()
{
bool isMenuActive = true;
@@ -12,7 +93,7 @@ void AdminMenu::run()
{
int choice;
util::clear();
std::cout << "Zenvy - HR Management System\n1. Create HRManager\n2. Create Employee\n3. View Employee\n4. Deactivate Employee\n5. Logout\nEnter your Choice: ";
std::cout << "Admin Menu\n1. Create User\n2. View Employee\n3. Deactivate Employee\n4. Logout\nEnter your Choice: ";
util::read(choice);
if (!handleOperation(choice))
{
@@ -31,22 +112,19 @@ bool AdminMenu::handleOperation(int choice)
{
switch (choice)
{
/*case 1:
m_zenvyController.createHRManager();
case 1:
createEmployee(m_zenvyController);
break;
case 2:
m_zenvyController.createEmployee();
break;
case 3:
/*case 2:
m_zenvyController.viewEmployee();
break;
case 4:
case 3:
m_zenvyController.deactivateEmployee();
break;*/
case 5:
case 4:
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
}
return true;
}
}
@@ -3,6 +3,84 @@
#include"InputHelper.h"
#include"OutputHelper.h"
static Enums::EmployeeType getEmployeeType()
{
int choice;
util::clear();
std::cout << "Select Employee Type"
"\n1. IT Executive"
"\n2. Team Executive"
"\n3. Finance Executive"
"\n4. Talent Executive"
"\n5. General Employee";
util::read(choice);
switch (choice)
{
case 1:
return Enums::EmployeeType::IT;
case 2:
return Enums::EmployeeType::TEAM;
case 3:
return Enums::EmployeeType::FINANCE;
case 4:
return Enums::EmployeeType::TAG;
case 5:
return Enums::EmployeeType::GENERAL;
default:
return Enums::EmployeeType::INVALID;
}
}
static Enums::EmployeeDesignation getEmployeeDesignation()
{
int choice;
util::clear();
std::cout << "Select Employee Designation"
"\n1. SENIOR"
"\n2. JUNIOR";
util::read(choice);
switch (choice)
{
case 1:
return Enums::EmployeeDesignation::SENIOR;
case 2:
return Enums::EmployeeDesignation::JUNIOR;
default:
return Enums::EmployeeDesignation::INVALID;
}
}
static void createEmployee(std::shared_ptr<ZenvyController> controller)
{
Enums::EmployeeType employeeType = 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, name, email, phone);
std::cout << "\nCreated Employee Successfully.";
}
void HRManagerMenu::run()
{
bool isMenuActive = true;
@@ -52,9 +130,9 @@ bool HRManagerMenu::handleOperation(int choice)
//case 7:
// m_zenvyController.viewAnnouncements();
// break;
//case 8:
// m_zenvyController.createEmployee();
// break;
case 8:
createEmployee(m_zenvyController);
break;
//case 9:
// m_zenvyController.regularizeAttenance();
// break;