Refactored validation logic and centralized employee validators
<SRS> SRS02 : Employee Management </SRS> <Changes> - Moved employee validation logic (active type check, email and phone duplication) to Validator utility - Updated service to use util::hasActiveEmployeeOfType, util::isEmailDuplicate, and util::isPhoneDuplicate - Integrated validator usage in MenuHelper for input validation - Cleaned up formatting and minor inconsistencies </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -9,45 +9,59 @@
|
||||
#include "MenuHelper.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "Validator.h"
|
||||
#include "Enums.h"
|
||||
|
||||
void createEmployee(std::shared_ptr<ZenvyController> controller);
|
||||
|
||||
inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
{
|
||||
int choice;
|
||||
std::string name, phone;
|
||||
name = m_zenvyController->getCurrentEmployee()->getEmployeeName();
|
||||
phone = m_zenvyController->getCurrentEmployee()->getEmployeePhone();
|
||||
while (true)
|
||||
int choice;
|
||||
std::string name, phone;
|
||||
name = m_zenvyController->getCurrentEmployee()->getEmployeeName();
|
||||
phone = m_zenvyController->getCurrentEmployee()->getEmployeePhone();
|
||||
while (true)
|
||||
{
|
||||
util::clear();
|
||||
std::cout << "Please choose the information you want to update:\n"
|
||||
"1. Name\n"
|
||||
"2. Phone Number\n"
|
||||
"3. Exit\n"
|
||||
"Enter your choice: ";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
std::cout << "Enter your updated Name :";
|
||||
util::read(name);
|
||||
m_zenvyController->updateProfile(name, phone);
|
||||
std::cout << "Profile Updated Successfully\n";
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "Enter your updated phone Number :";
|
||||
util::read(phone);
|
||||
m_zenvyController->updateProfile(name, phone);
|
||||
std::cout << "Profile Updated Successfully\n";
|
||||
break;
|
||||
case 3:
|
||||
return;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
break;
|
||||
}
|
||||
util::clear();
|
||||
std::cout << "Please choose the information you want to update:\n"
|
||||
"1. Name\n"
|
||||
"2. Phone Number\n"
|
||||
"3. Exit\n"
|
||||
"Enter your choice: ";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
std::cout << "Enter your updated Name: ";
|
||||
util::read(name);
|
||||
m_zenvyController->updateProfile(name, phone);
|
||||
std::cout << "Profile Updated Successfully\n";
|
||||
util::pressEnter();
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "Enter your updated phone Number: ";
|
||||
util::read(phone);
|
||||
if (!util::isPhoneNumberValid(phone))
|
||||
{
|
||||
std::cout << "Error: Invalid Phone Number";
|
||||
util::pressEnter();
|
||||
}
|
||||
if (util::isPhoneDuplicate(phone, m_zenvyController->getEmployees()))
|
||||
{
|
||||
std::cout << "Error: Duplicate Phone Number!";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
m_zenvyController->updateProfile(name, phone);
|
||||
std::cout << "Profile Updated Successfully\n";
|
||||
util::pressEnter();
|
||||
break;
|
||||
case 3:
|
||||
return;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user