Bankkonto-Inhaber beim GoCardless-Sync aktualisieren
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 44s
Build and Push Docker Images / build-website (push) Successful in 22s
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 22s
Build and Push Docker Images / build-frontend (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 22s

This commit is contained in:
root
2026-09-01 06:27:27 +00:00
parent 95ca7a4aaf
commit 92686ead9a
2 changed files with 55 additions and 0 deletions

View File

@@ -52,6 +52,11 @@ const normalizeDate = (val: any) => {
return isNaN(d.getTime()) ? null : d
}
export const getBankAccountOwnerName = (account: any) => {
const ownerName = typeof account?.owner_name === "string" ? account.owner_name.trim() : ""
return ownerName || null
}
export function bankStatementService(server: FastifyInstance) {
let accessToken: string | null = null
@@ -110,6 +115,23 @@ export function bankStatementService(server: FastifyInstance) {
}
}
// -----------------------------------------------
// ✔ Kontoinhaber laden
// -----------------------------------------------
const getAccountData = async (accountId: string): Promise<any> => {
if (useCentralBanking) return await centralServicesClient.getBankingAccount(accountId)
const {data} = await axios.get(
`${secrets.GOCARDLESS_BASE_URL}/accounts/${accountId}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
Accept: "application/json",
},
}
)
return data
}
// -----------------------------------------------
// ✔ Transaktionen laden
// -----------------------------------------------
@@ -162,6 +184,22 @@ export function bankStatementService(server: FastifyInstance) {
for (const account of accounts) {
try {
// ---------------------------
// 0. KONTOINHABER SYNC
// ---------------------------
try {
const accountData = await getAccountData(account.accountId)
const ownerName = getBankAccountOwnerName(accountData)
if (ownerName && ownerName !== account.ownerName) {
await server.db
.update(bankaccounts)
.set({ownerName})
.where(eq(bankaccounts.id, account.id))
}
} catch (error: any) {
server.log.warn({err: error, accountId: account.accountId}, "Kontoinhaber konnte nicht synchronisiert werden")
}
// ---------------------------
// 1. BALANCE SYNC
// ---------------------------

View File

@@ -0,0 +1,17 @@
import test from "node:test"
import assert from "node:assert/strict"
import { getBankAccountOwnerName } from "../src/modules/cron/bankstatementsync.service"
test("reads the GoCardless owner_name for a bank account", () => {
assert.equal(
getBankAccountOwnerName({ owner_name: "Neue Firma GmbH" }),
"Neue Firma GmbH"
)
})
test("does not overwrite the stored owner with an empty provider value", () => {
assert.equal(getBankAccountOwnerName({ owner_name: "" }), null)
assert.equal(getBankAccountOwnerName({}), null)
assert.equal(getBankAccountOwnerName(null), null)
})