Bankkonto-Aktualisierung über zentralen Dienst reparieren
All checks were successful
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 22s
Build and Push Docker Images / build-backend (push) Successful in 44s
Build and Push Docker Images / build-frontend (push) Successful in 1m13s
Build and Push Docker Images / build-central-services-api (push) Successful in 21s
All checks were successful
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 22s
Build and Push Docker Images / build-backend (push) Successful in 44s
Build and Push Docker Images / build-frontend (push) Successful in 1m13s
Build and Push Docker Images / build-central-services-api (push) Successful in 21s
This commit is contained in:
@@ -57,6 +57,16 @@ export const getBankAccountOwnerName = (account: any) => {
|
||||
return ownerName || null
|
||||
}
|
||||
|
||||
export const isExpiredBankingError = (error: any) => {
|
||||
const values = [
|
||||
error?.response?.data?.summary,
|
||||
error?.response?.data?.detail,
|
||||
error?.response?.data?.message,
|
||||
error?.message,
|
||||
]
|
||||
return values.some((value) => typeof value === "string" && value.toLowerCase().includes("expired"))
|
||||
}
|
||||
|
||||
export function bankStatementService(server: FastifyInstance) {
|
||||
|
||||
let accessToken: string | null = null
|
||||
@@ -83,7 +93,7 @@ export function bankStatementService(server: FastifyInstance) {
|
||||
// -----------------------------------------------
|
||||
// ✔ Salden laden
|
||||
// -----------------------------------------------
|
||||
const getBalanceData = async (accountId: string): Promise<any> => {
|
||||
const getBalanceData = async (accountId: string, tenantId: number): Promise<any> => {
|
||||
try {
|
||||
if (useCentralBanking) return await centralServicesClient.getBankingBalances(accountId)
|
||||
const {data} = await axios.get(
|
||||
@@ -100,15 +110,14 @@ export function bankStatementService(server: FastifyInstance) {
|
||||
} catch (err: any) {
|
||||
server.log.error(err.response?.data ?? err)
|
||||
|
||||
const expired =
|
||||
err.response?.data?.summary?.includes("expired") ||
|
||||
err.response?.data?.detail?.includes("expired")
|
||||
|
||||
if (expired) {
|
||||
if (isExpiredBankingError(err)) {
|
||||
await server.db
|
||||
.update(bankaccounts)
|
||||
.set({expired: true})
|
||||
.where(eq(bankaccounts.accountId, accountId))
|
||||
.where(and(
|
||||
eq(bankaccounts.accountId, accountId),
|
||||
eq(bankaccounts.tenant, tenantId),
|
||||
))
|
||||
}
|
||||
|
||||
throw err
|
||||
@@ -203,7 +212,7 @@ export function bankStatementService(server: FastifyInstance) {
|
||||
// ---------------------------
|
||||
// 1. BALANCE SYNC
|
||||
// ---------------------------
|
||||
const balData = await getBalanceData(account.accountId)
|
||||
const balData = await getBalanceData(account.accountId, tenantId)
|
||||
|
||||
if (balData) {
|
||||
const closing = balData.balances.find(
|
||||
|
||||
Reference in New Issue
Block a user