Zentralen BIC-Abgleich robust machen
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 44s
Build and Push Docker Images / build-frontend (push) Successful in 22s
Build and Push Docker Images / build-website (push) Successful in 21s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 23s
Build and Push Docker Images / build-docs (push) Successful in 21s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 44s
Build and Push Docker Images / build-frontend (push) Successful in 22s
Build and Push Docker Images / build-website (push) Successful in 21s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 23s
Build and Push Docker Images / build-docs (push) Successful in 21s
This commit is contained in:
22
backend/src/modules/banking-institution.ts
Normal file
22
backend/src/modules/banking-institution.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
export type BankingInstitution = {
|
||||||
|
bic?: unknown
|
||||||
|
[key: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
export const findBankInstitutionByBic = (
|
||||||
|
institutions: unknown,
|
||||||
|
bic: string,
|
||||||
|
): BankingInstitution | null => {
|
||||||
|
if (!Array.isArray(institutions)) return null
|
||||||
|
|
||||||
|
const normalizedBic = bic.trim().toUpperCase()
|
||||||
|
if (!normalizedBic) return null
|
||||||
|
|
||||||
|
const institution = institutions.find((candidate): candidate is BankingInstitution => {
|
||||||
|
if (!candidate || typeof candidate !== "object") return false
|
||||||
|
const candidateBic = (candidate as BankingInstitution).bic
|
||||||
|
return typeof candidateBic === "string" && candidateBic.trim().toUpperCase() === normalizedBic
|
||||||
|
})
|
||||||
|
|
||||||
|
return institution || null
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import { decrypt, encrypt } from "../utils/crypt"
|
|||||||
import { DE_BANK_CODE_TO_NAME } from "../utils/deBankCodes"
|
import { DE_BANK_CODE_TO_NAME } from "../utils/deBankCodes"
|
||||||
import { DE_BANK_CODE_TO_BIC } from "../utils/deBankBics"
|
import { DE_BANK_CODE_TO_BIC } from "../utils/deBankBics"
|
||||||
import { centralServicesClient } from "../modules/push-server.client"
|
import { centralServicesClient } from "../modules/push-server.client"
|
||||||
|
import { findBankInstitutionByBic } from "../modules/banking-institution"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bankrequisitions,
|
bankrequisitions,
|
||||||
@@ -1047,7 +1048,7 @@ export default async function bankingRoutes(server: FastifyInstance) {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
const bank = data.find((i: any) => i.bic.toLowerCase() === bic.toLowerCase())
|
const bank = findBankInstitutionByBic(data, bic)
|
||||||
|
|
||||||
if (!bank) return reply.code(404).send("Bank not found")
|
if (!bank) return reply.code(404).send("Bank not found")
|
||||||
|
|
||||||
|
|||||||
18
backend/tests/bankingInstitution.test.ts
Normal file
18
backend/tests/bankingInstitution.test.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import test from "node:test"
|
||||||
|
import assert from "node:assert/strict"
|
||||||
|
|
||||||
|
import { findBankInstitutionByBic } from "../src/modules/banking-institution"
|
||||||
|
|
||||||
|
test("finds a banking institution by BIC case-insensitively", () => {
|
||||||
|
const institution = findBankInstitutionByBic([
|
||||||
|
{ id: "without-bic" },
|
||||||
|
{ id: "slz", bic: "slzode22xxx" },
|
||||||
|
], " SLZODE22XXX ")
|
||||||
|
|
||||||
|
assert.equal(institution?.id, "slz")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("ignores institutions without a BIC instead of throwing", () => {
|
||||||
|
assert.equal(findBankInstitutionByBic([{ id: "without-bic" }], "SLZODE22XXX"), null)
|
||||||
|
assert.equal(findBankInstitutionByBic(null, "SLZODE22XXX"), null)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user