fixed bug when monitoring uses wrong username to show it to a user

This commit is contained in:
Eugene Zadyra
2023-03-22 22:10:39 +01:00
parent c1ceb3d7b6
commit 38e59f148d
2 changed files with 5 additions and 7 deletions

View File

@@ -265,11 +265,13 @@ class DataRepository(@Autowired em: EntityManager) {
.toSeq
}
def getUsernameById(userId: Long): Option[String] = {
def getUsernameByUserIdAndAccountId(userId: Long, accountId: Long): Option[String] = {
em.createQuery(
"select credentials.username from Credentials credentials where credentials.userId = :userId",
"""select credentials.username from Credentials credentials where credentials.userId = :userId
| and credentials.accountId = :accountId""".stripMargin,
classOf[String]
).setParameter("userId", userId)
.setParameter("accountId", accountId)
.getResultList
.asScala
.headOption

View File

@@ -84,7 +84,7 @@ class DataService {
for {
userId <- dataRepository.findUserId(source.chatId, source.sourceSystem.id).map(_.toLong)
accountId <- dataRepository.findAccountId(userId).map(_.toLong)
username <- dataRepository.getUsernameById(userId)
username <- dataRepository.getUsernameByUserIdAndAccountId(userId, accountId)
} yield (userId, username, accountId)
}
@@ -96,10 +96,6 @@ class DataService {
dataRepository.getUserCredentials(userId)
}
def getUsernameById(userId: Long): Option[String] = {
dataRepository.getUsernameById(userId)
}
def findUserCredentialsByAccountId(userId: Long, accountId: Long): Option[Credentials] = {
dataRepository.findUserCredentialsByUserIdAndAccountId(userId, accountId)
}