Merge branch 'feature-customer-management-cus004' into feature-customer-management
This commit is contained in:
+32
-1
@@ -1,7 +1,12 @@
|
||||
#include "UserManagementService.h"
|
||||
#include <stdexcept>
|
||||
#include "User.h"
|
||||
#include "Enums.h"
|
||||
#include "Config.h"
|
||||
#include "UserManagementService.h"
|
||||
#include "ServiceManagementService.h"
|
||||
#include "PaymentManagementService.h"
|
||||
#include "InventoryManagementService.h"
|
||||
#include "Factory.h"
|
||||
|
||||
void UserManagementService::ensureAdminExists()
|
||||
{
|
||||
@@ -28,3 +33,29 @@ void UserManagementService::ensureAdminExists()
|
||||
util::UserType::ADMIN);
|
||||
}
|
||||
}
|
||||
|
||||
void UserManagementService::createUser(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone, util::UserType type)
|
||||
{
|
||||
InventoryManagementService inventoryManagementService;
|
||||
PaymentManagementService paymentManagementService;
|
||||
ServiceManagementService serviceManagementService;
|
||||
auto& usersMap = m_dataStore.getUsers();
|
||||
int index = usersMap.findIf(
|
||||
[&](const std::string&, User* user)
|
||||
{
|
||||
return user->getUserName() == username;
|
||||
}
|
||||
);
|
||||
if (index != -1)
|
||||
{
|
||||
throw std::runtime_error("Username already exists");
|
||||
}
|
||||
User* newUser = Factory::getObject<User>(username, password, name, phone, email, type);
|
||||
usersMap.insert(newUser->getId(), newUser);
|
||||
paymentManagementService.attach(newUser);
|
||||
serviceManagementService.attach(newUser);
|
||||
if (newUser->getUserType() == util::UserType::ADMIN)
|
||||
{
|
||||
inventoryManagementService.attach(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user