fixed error nominee add error
This commit is contained in:
+12
-9
@@ -41,22 +41,25 @@ public interface ClientNomineeRepository extends JpaRepository<ClientNominee, Lo
|
|||||||
@Query("SELECT n FROM ClientNominee n WHERE n.client.id = :clientId AND n.accountNo = :accountNo AND n.accountType = :accountType AND n.isDeleted = false ORDER BY n.id")
|
@Query("SELECT n FROM ClientNominee n WHERE n.client.id = :clientId AND n.accountNo = :accountNo AND n.accountType = :accountType AND n.isDeleted = false ORDER BY n.id")
|
||||||
List<ClientNominee> findByClientIdAndAccountNoAndAccountType(@Param("clientId") Long clientId, @Param("accountNo") String accountNo, @Param("accountType") String accountType);
|
List<ClientNominee> findByClientIdAndAccountNoAndAccountType(@Param("clientId") Long clientId, @Param("accountNo") String accountNo, @Param("accountType") String accountType);
|
||||||
|
|
||||||
@Query("SELECT COUNT(n) FROM ClientNominee n WHERE n.accountNo = :accountNo AND n.accountType = :accountType AND n.isDeleted = false")
|
@Query("SELECT COUNT(n) FROM ClientNominee n WHERE n.accountNo = :accountNo AND n.accountType = :accountType")
|
||||||
long countByAccountNoAndAccountType(@Param("accountNo") String accountNo, @Param("accountType") String accountType);
|
long countByAccountNoAndAccountType(@Param("accountNo") String accountNo, @Param("accountType") String accountType);
|
||||||
|
|
||||||
/**
|
@Query("SELECT COUNT(n) FROM ClientNominee n "
|
||||||
* Counts non-deleted nominee rows that link {@code nomineeClientId} as a nominee under
|
+ "WHERE n.client.id = :clientId "
|
||||||
* {@code clientId} for the given {@code accountType}. Backs the rule that the same person
|
+ "AND n.nomineeClient.id = :nomineeClientId "
|
||||||
* may not be linked as a nominee more than once per (account owner, account type).
|
+ "AND n.accountType = :accountType "
|
||||||
* {@code excludeNomineeId} is set on update so a row doesn't conflict with itself.
|
+ "AND n.isDeleted = false")
|
||||||
*/
|
long countActiveByClientNomineeAndAccountType(@Param("clientId") Long clientId,
|
||||||
|
@Param("nomineeClientId") Long nomineeClientId,
|
||||||
|
@Param("accountType") String accountType);
|
||||||
|
|
||||||
@Query("SELECT COUNT(n) FROM ClientNominee n "
|
@Query("SELECT COUNT(n) FROM ClientNominee n "
|
||||||
+ "WHERE n.client.id = :clientId "
|
+ "WHERE n.client.id = :clientId "
|
||||||
+ "AND n.nomineeClient.id = :nomineeClientId "
|
+ "AND n.nomineeClient.id = :nomineeClientId "
|
||||||
+ "AND n.accountType = :accountType "
|
+ "AND n.accountType = :accountType "
|
||||||
+ "AND n.isDeleted = false "
|
+ "AND n.isDeleted = false "
|
||||||
+ "AND (:excludeNomineeId IS NULL OR n.id <> :excludeNomineeId)")
|
+ "AND n.id <> :excludeNomineeId")
|
||||||
long countActiveByClientNomineeAndAccountType(@Param("clientId") Long clientId,
|
long countActiveByClientNomineeAndAccountTypeExcluding(@Param("clientId") Long clientId,
|
||||||
@Param("nomineeClientId") Long nomineeClientId,
|
@Param("nomineeClientId") Long nomineeClientId,
|
||||||
@Param("accountType") String accountType,
|
@Param("accountType") String accountType,
|
||||||
@Param("excludeNomineeId") Long excludeNomineeId);
|
@Param("excludeNomineeId") Long excludeNomineeId);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+5
-2
@@ -287,8 +287,11 @@ public class ClientNomineeWritePlatformServiceImpl implements ClientNomineeWrite
|
|||||||
if (clientId == null || nomineeClientId == null || accountType == null || accountType.isBlank()) {
|
if (clientId == null || nomineeClientId == null || accountType == null || accountType.isBlank()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final long existing = nomineeRepository.countActiveByClientNomineeAndAccountType(
|
final long existing = (excludeNomineeId != null)
|
||||||
clientId, nomineeClientId, accountType, excludeNomineeId);
|
? nomineeRepository.countActiveByClientNomineeAndAccountTypeExcluding(
|
||||||
|
clientId, nomineeClientId, accountType, excludeNomineeId)
|
||||||
|
: nomineeRepository.countActiveByClientNomineeAndAccountType(
|
||||||
|
clientId, nomineeClientId, accountType);
|
||||||
if (existing > 0) {
|
if (existing > 0) {
|
||||||
throw new PlatformDataIntegrityException("error.msg.nominee.already.linked.for.account.type",
|
throw new PlatformDataIntegrityException("error.msg.nominee.already.linked.for.account.type",
|
||||||
"This person is already a nominee for one of the client's "
|
"This person is already a nominee for one of the client's "
|
||||||
|
|||||||
Reference in New Issue
Block a user