feature/If a recurring consent already exists for the same PSU (from the same TPP)

This commit is contained in:
Marko Milić 2025-04-28 22:00:04 +02:00
parent ac4c632985
commit 29ec546aa8
3 changed files with 24 additions and 0 deletions

View File

@ -1036,6 +1036,25 @@ object Consent extends MdcLoggable {
consentsOfBank
}
def expireAllPreviousValidBerlinGroupConsents(consent: MappedConsent): Boolean = {
if(consent.status == ConsentStatus.valid.toString &&
consent.apiStandard == ApiVersion.berlinGroupV13.apiStandard) {
MappedConsent.findAll( // Find all
By(MappedConsent.mApiStandard, ApiVersion.berlinGroupV13.apiStandard), // Berlin Group
By(MappedConsent.mRecurringIndicator, true), // recurring
By(MappedConsent.mStatus, ConsentStatus.valid.toString), // and valid consents
By(MappedConsent.mUserId, consent.userId), // for the same PSU
By(MappedConsent.mConsumerId, consent.consumerId), // from the same TPP
).filterNot(_.consentId == consent.consentId) // Exclude current consent
.map(c => // Set to expired
c.mStatus(ConsentStatus.expired.toString)
.mLastActionDate(new Date()).save
).forall(_ == true)
} else {
true
}
}
/*
// Example Usage
val box1: Box[String] = Full("Hello, World!")

View File

@ -2,6 +2,7 @@ package code.api.util
import java.math.BigInteger
import net.liftweb.common.Box
import org.iban4j.IbanUtil
object HashUtil {
def Sha256Hash(in: String): String = {
@ -25,5 +26,8 @@ object HashUtil {
val hashedText = Sha256Hash(plainText)
println("Password: " + plainText)
println("Hashed password: " + hashedText)
println("BBAN: " + IbanUtil.getBban("AT483200000012345864"))
println("Bank code: " + IbanUtil.getBankCode("AT483200000012345864"))
println("Country code: " + IbanUtil.getCountryCode("AT483200000012345864"))
}
}

View File

@ -30,6 +30,7 @@ object MappedConsentProvider extends ConsentProvider {
override def updateConsentStatus(consentId: String, status: ConsentStatus): Box[MappedConsent] = {
MappedConsent.find(By(MappedConsent.mConsentId, consentId)) match {
case Full(consent) =>
Consent.expireAllPreviousValidBerlinGroupConsents(consent)
tryo(consent
.mStatus(status.toString)
.mLastActionDate(now) //maybe not right, but for the create we use the `now`, we need to update it later.