TP-69510 | Vedant Aggarwal | Sorting Linked Accounts (#12528)

This commit is contained in:
vedant aggarwal
2024-09-13 13:01:33 +05:30
committed by GitHub
parent 0e28457c7c
commit 1993d97758

View File

@@ -123,7 +123,8 @@ constructor(
val sortedLinkedAccounts =
sortLinkedAccounts(
linkedAccounts = linkedAccounts,
accountTypePriorityStack = accountTypePriorityStack
accountTypePriorityStack = accountTypePriorityStack,
includeAllDetails = includeAllDetails
)
if (!includeAllDetails) {
@@ -167,22 +168,27 @@ constructor(
private fun sortLinkedAccounts(
linkedAccounts: List<LinkedAccountEntity>,
accountTypePriorityStack: Map<String, Int>
accountTypePriorityStack: Map<String, Int>,
includeAllDetails: Boolean
): List<LinkedAccountEntity> {
return linkedAccounts.sortedWith(
compareBy(
{ // Sort by priority stack
accountTypePriorityStack[AccountType.getAccountType(it.accountType).name]
?: Int.MAX_VALUE
},
{ // Place primary accounts first within the same account type
!it.isAccountPrimary
},
{ // Sort by updatedTimestampDateTimeUTC from oldest to newest
it.updatedAt
}
return if (includeAllDetails) {
linkedAccounts.sortedWith(
compareBy(
{ // Sort by priority stack
accountTypePriorityStack[AccountType.getAccountType(it.accountType).name]
?: Int.MAX_VALUE
},
{ // Place primary accounts first within the same account type
!it.isAccountPrimary
},
{ // Sort by updatedTimestampDateTimeUTC from oldest to newest
it.updatedAt
}
)
)
)
} else {
linkedAccounts.sortedBy { !it.isAccountPrimary }
}
}
private suspend fun updateBankUptimeStatusToLinkedAccounts(