This commit is contained in:
@@ -17,6 +17,7 @@ import ru.soune.nocopy.entity.user.AuthToken;
|
||||
import ru.soune.nocopy.entity.user.Permission;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.entity.user.UserNotActive;
|
||||
import ru.soune.nocopy.exception.CompanyAlreadyExist;
|
||||
import ru.soune.nocopy.exception.NotFoundAuthToken;
|
||||
import ru.soune.nocopy.exception.NotValidFieldException;
|
||||
import ru.soune.nocopy.repository.*;
|
||||
@@ -61,7 +62,11 @@ public class AuthService {
|
||||
AccountType accountType = AccountType.valueOf(registerRequest.getAccountType().toUpperCase());
|
||||
|
||||
if (accountType == AccountType.B2B && registerRequest.getCompanyName() != null) {
|
||||
createCompanyAccount(registerRequest, user);
|
||||
try {
|
||||
createCompanyAccount(registerRequest, user);
|
||||
} catch (CompanyAlreadyExist exist) {
|
||||
throw new CompanyAlreadyExist("Company already exist");
|
||||
}
|
||||
} else if (accountType == AccountType.B2C && registerRequest.getCompanyName() == null) {
|
||||
createIndividualAccount(user);
|
||||
} else {
|
||||
@@ -173,7 +178,7 @@ public class AuthService {
|
||||
Optional<Company> byInn = companyRepository.findByInn(request.getInn());
|
||||
|
||||
if (byInn.isPresent()) {
|
||||
throw new IllegalStateException("Company was already created");
|
||||
throw new CompanyAlreadyExist("Company was already created");
|
||||
}
|
||||
|
||||
Company company = new Company();
|
||||
|
||||
Reference in New Issue
Block a user