fixed error nominee add error

This commit is contained in:
Nitesh Yadav
2026-05-15 16:09:13 +05:30
parent 001a79e35e
commit 4eeee03f24
3 changed files with 12335 additions and 11 deletions
@@ -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")
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);
/**
* Counts non-deleted nominee rows that link {@code nomineeClientId} as a nominee under
* {@code clientId} for the given {@code accountType}. Backs the rule that the same person
* may not be linked as a nominee more than once per (account owner, account type).
* {@code excludeNomineeId} is set on update so a row doesn't conflict with itself.
*/
@Query("SELECT COUNT(n) FROM ClientNominee n "
+ "WHERE n.client.id = :clientId "
+ "AND n.nomineeClient.id = :nomineeClientId "
+ "AND n.accountType = :accountType "
+ "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 "
+ "WHERE n.client.id = :clientId "
+ "AND n.nomineeClient.id = :nomineeClientId "
+ "AND n.accountType = :accountType "
+ "AND n.isDeleted = false "
+ "AND (:excludeNomineeId IS NULL OR n.id <> :excludeNomineeId)")
long countActiveByClientNomineeAndAccountType(@Param("clientId") Long clientId,
+ "AND n.id <> :excludeNomineeId")
long countActiveByClientNomineeAndAccountTypeExcluding(@Param("clientId") Long clientId,
@Param("nomineeClientId") Long nomineeClientId,
@Param("accountType") String accountType,
@Param("excludeNomineeId") Long excludeNomineeId);
File diff suppressed because it is too large Load Diff
@@ -287,8 +287,11 @@ public class ClientNomineeWritePlatformServiceImpl implements ClientNomineeWrite
if (clientId == null || nomineeClientId == null || accountType == null || accountType.isBlank()) {
return;
}
final long existing = nomineeRepository.countActiveByClientNomineeAndAccountType(
clientId, nomineeClientId, accountType, excludeNomineeId);
final long existing = (excludeNomineeId != null)
? nomineeRepository.countActiveByClientNomineeAndAccountTypeExcluding(
clientId, nomineeClientId, accountType, excludeNomineeId)
: nomineeRepository.countActiveByClientNomineeAndAccountType(
clientId, nomineeClientId, accountType);
if (existing > 0) {
throw new PlatformDataIntegrityException("error.msg.nominee.already.linked.for.account.type",
"This person is already a nominee for one of the client's "