Fix Update Profile and User Validation Issues

- Included Validator.h in UserManagementService.cpp for duplicate checks.
- Enhanced updateUserDetails in UserManagementService to validate:
  - Throw error if user does not exist.
  - Throw error if email already exists among active users.
  - Throw error if phone number already exists among active users.
- Implemented new duplicate validation functions in Validator.cpp:
  - isUsernameDuplicate
  - isPhoneDuplicate
  - isEmailDuplicate
- Declared new duplicate validation functions in Validator.h.
- Updated CustomerMenu::updateDetails:
  - Added "Update Details" header for clarity.
  - Improved error messages with newline formatting.
  - Added success message with newline formatting.

Fixes #1746
This commit is contained in:
Avinash Rajesh
2026-05-26 20:03:02 +05:30
committed by Joel Thomas
parent 80b91f3f1b
commit 33cbb1dac3
3 changed files with 48 additions and 5 deletions
@@ -111,7 +111,15 @@ void UserManagementService::updateUserDetails(const std::string& userID, const s
int index = usersMap.find(userID);
if (index == -1)
{
throw std::runtime_error("User does not exist!");
throw std::runtime_error("User does not exist!\n");
}
if (util::isEmailDuplicate(email, usersMap))
{
throw std::runtime_error("Email already exists!\n");
}
if (util::isPhoneDuplicate(phone, usersMap))
{
throw std::runtime_error("Phone number already exists!\n");
}
User* user = usersMap.getValueAt(index);
user->setEmail(email);