libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit c7f37ecfb619cc1426d9b76c7285df4bbc499b8f
parent 7ec8e050a3cae07b2ec02867a1a9f4010743da94
Author: MS <ms@taler.net>
Date:   Mon,  1 Jun 2020 17:10:12 +0200

avoid confusing helper

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 4----
Mnexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | 15++++++++++-----
2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -61,10 +61,6 @@ object TalerIncomingPayments : LongIdTable() { val refunded = bool("refunded").default(false) } -fun LongEntityClass<*>.getLast(): Long { - return this.all().maxBy { it.id }?.id?.value ?: -1 -} - class TalerIncomingPaymentEntity(id: EntityID<Long>) : LongEntity(id) { companion object : LongEntityClass<TalerIncomingPaymentEntity>(TalerIncomingPayments) { override fun new(init: TalerIncomingPaymentEntity.() -> Unit): TalerIncomingPaymentEntity { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt @@ -351,7 +351,7 @@ suspend fun talerAddIncoming(call: ApplicationCall): Unit { */ fun ingestTalerTransactions() { fun ingestIncoming(subscriberAccount: NexusBankAccountEntity) { - val latestIncomingPaymentId: Long = TalerIncomingPaymentEntity.getLast() + val latestIncomingPayment = TalerIncomingPaymentEntity.all().maxBy { it.payment.id.value } RawBankTransactionEntity.find { /** Those with exchange bank account involved */ RawBankTransactionsTable.bankAccount eq subscriberAccount.id.value and @@ -360,7 +360,10 @@ fun ingestTalerTransactions() { /** Those that are booked */ (RawBankTransactionsTable.status eq "BOOK") and /** Those that came later than the latest processed payment */ - (RawBankTransactionsTable.id.greater(latestIncomingPaymentId)) + (RawBankTransactionsTable.id.greater( + if (latestIncomingPayment == null) 0 + else latestIncomingPayment.payment.id.value + )) }.forEach { if (duplicatePayment(it)) { logger.warn("Incoming payment already seen") @@ -381,13 +384,15 @@ fun ingestTalerTransactions() { } } } - } fun ingestOutgoing(subscriberAccount: NexusBankAccountEntity) { - val latestOutgoingPaymentId = TalerRequestedPaymentEntity.getLast() + val latestOutgoingPayment = TalerIncomingPaymentEntity.all().maxBy { it.payment.id.value } RawBankTransactionEntity.find { /** Those that came after the last processed payment */ - RawBankTransactionsTable.id greater latestOutgoingPaymentId and + RawBankTransactionsTable.id.greater( + if (latestOutgoingPayment == null) 0 + else latestOutgoingPayment.payment.id.value + ) and /** Those involving the exchange bank account */ (RawBankTransactionsTable.bankAccount eq subscriberAccount.id.value) and /** Those that are outgoing */