improving logical flow of transactions & onboarding
This commit is contained in:
@@ -29,6 +29,13 @@ public class TransactionService {
|
||||
private final TransactionRepository transactionRepository;
|
||||
private final AdditionalDataService additionalDataService;
|
||||
|
||||
public void reassignTransactions(String oldUid, String newUid){
|
||||
List<Transaction> transactions = transactionRepository.findAllByUserId(oldUid);
|
||||
transactions.forEach(transaction -> {
|
||||
transaction.setUserId(newUid);
|
||||
transactionRepository.save(transaction);
|
||||
});
|
||||
}
|
||||
|
||||
public Transaction findById(UUID id) {
|
||||
Transaction transaction = transactionRepository.findById(id).orElseThrow(() -> new ApiException("Transaction not found for ID: " + id));
|
||||
|
||||
@@ -22,6 +22,7 @@ public class UserService implements UserDetailsService {
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final TransactionService transactionService;
|
||||
|
||||
public User fetchUserByUsername(String username) {
|
||||
return userRepository.findByUsername(username)
|
||||
@@ -52,10 +53,19 @@ public class UserService implements UserDetailsService {
|
||||
user.setPhone(request.getPhone());
|
||||
user.setWorkflowId(request.getWorkflowId());
|
||||
user.setPhotoUrl(request.getPhotoUrl());
|
||||
user.setDeleted(false);
|
||||
|
||||
User savedUser = userRepository.save(user);
|
||||
String token = jwtUtils.generateToken(savedUser);
|
||||
|
||||
// reassign anonymous transactions to the new user
|
||||
// if we fail we move on, not a critical step
|
||||
try {
|
||||
transactionService.reassignTransactions(request.getTempUid(), savedUser.getId().toString());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return new AuthResponse(token, "Bearer", savedUser.getUsername(),
|
||||
savedUser.getEmail(), savedUser.getPhone(), savedUser.getFirstName(), savedUser.getLastName(), savedUser.getId());
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ZesaConfirmationProcessor implements TransactionProcessorInterface
|
||||
transaction.setStatus(Status.SUCCESS);
|
||||
transaction.setResponseCode((String) body.get("responseCode"));
|
||||
transaction.setAdditionalData(body.get("additionalData"));
|
||||
transactionService.save(transaction);
|
||||
transaction.setCreditPhone(transaction.getDebitPhone());
|
||||
|
||||
AdditionalData additionalData = AdditionalData.builder()
|
||||
.transactionId(transaction.getId().toString())
|
||||
@@ -81,7 +81,7 @@ public class ZesaConfirmationProcessor implements TransactionProcessorInterface
|
||||
transaction.setErrorMessage((String) body.get("errorMessage"));
|
||||
}
|
||||
|
||||
return transactionService.save(transaction);
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user