Implement review fixes
Changes: - Strengthened UserManagementService::updateUserDetails by checking duplicates only when email/phone are changed, preventing false errors - Updated AdminMenu::viewStockLevels header text from "View Stock Level" to "View Stock Levels" for consistency - Cleaned up CustomerMenu::updateDetails by removing unused user list retrieval and improving header/message formatting
This commit is contained in:
+14
-8
@@ -113,15 +113,21 @@ void UserManagementService::updateUserDetails(const std::string& userID, const s
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("User does not exist!\n");
|
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* user = usersMap.getValueAt(index);
|
||||||
|
if (email != user->getEmail())
|
||||||
|
{
|
||||||
|
if (util::isEmailDuplicate(email, usersMap))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Email already exists!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (phone != user->getPhone())
|
||||||
|
{
|
||||||
|
if (util::isPhoneDuplicate(phone, usersMap))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Phone number already exists!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
user->setEmail(email);
|
user->setEmail(email);
|
||||||
user->setPhone(phone);
|
user->setPhone(phone);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ void AdminMenu::viewStockLevels()
|
|||||||
util::clear();
|
util::clear();
|
||||||
auto inventoryItems = m_controller.getInventoryItems();
|
auto inventoryItems = m_controller.getInventoryItems();
|
||||||
bool hasActiveItems = false;
|
bool hasActiveItems = false;
|
||||||
std::cout << "View Stock Level" << std::endl;
|
std::cout << "View Stock Levels" << std::endl;
|
||||||
if (inventoryItems.isEmpty())
|
if (inventoryItems.isEmpty())
|
||||||
{
|
{
|
||||||
std::cout << "No items found in Inventory.\n";
|
std::cout << "No items found in Inventory.\n";
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ Return type: void
|
|||||||
void CustomerMenu::updateDetails()
|
void CustomerMenu::updateDetails()
|
||||||
{
|
{
|
||||||
std::string email, phone;
|
std::string email, phone;
|
||||||
util::Map<std::string, const User*> userList = m_controller.getUsers();
|
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Update Details\n";
|
std::cout << "Update Details\n";
|
||||||
std::cout << "Enter new email: ";
|
std::cout << "Enter new email: ";
|
||||||
|
|||||||
Reference in New Issue
Block a user