🐛 Do not upload transactions that are not booked
All checks were successful
Deploy application / deploy (push) Successful in 8s
All checks were successful
Deploy application / deploy (push) Successful in 8s
This commit is contained in:
parent
a0cefcdfa1
commit
080b65854d
@ -1,10 +1,10 @@
|
||||
import type { UUID } from "node:crypto"
|
||||
import dayjs from "dayjs"
|
||||
import { ACTUAL_ACCOUNT_IDS, BANK_ACCOUNT_IDS } from "@/config.ts"
|
||||
import logger from "@common/logger.ts"
|
||||
import { toISODateString } from "@common/date.ts"
|
||||
import type { SB1Transaction } from "@sb1/types.ts"
|
||||
import dayjs from "dayjs"
|
||||
|
||||
import type { ActualTransaction } from "@common/types.ts"
|
||||
import type { SB1Transaction } from "@sb1/types.ts"
|
||||
import type { UUID } from "node:crypto"
|
||||
|
||||
export function bankTransactionIntoActualTransaction(
|
||||
transaction: SB1Transaction,
|
||||
@ -18,7 +18,6 @@ export function bankTransactionIntoActualTransaction(
|
||||
amount: Math.floor(transaction.amount * 100),
|
||||
date: toISODateString(dayjs(transaction.date)),
|
||||
payee_name: transaction.cleanedDescription,
|
||||
// TODO if not cleared or nonUniqueId is 0, rerun later
|
||||
cleared: isCleared(transaction),
|
||||
}
|
||||
}
|
||||
@ -38,9 +37,7 @@ function getActualAccountId(transcation: SB1Transaction): UUID {
|
||||
return ACTUAL_ACCOUNT_IDS[i] as UUID
|
||||
}
|
||||
}
|
||||
const error = new Error(
|
||||
throw new Error(
|
||||
"Failed to find ActualAccountId, length of BANK_ACCOUNT_IDS and ACTUAL_ACCOUNT_IDS must match",
|
||||
)
|
||||
logger.error(error)
|
||||
throw error
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import * as Transactions from "@sb1/transactions.ts"
|
||||
import * as Oauth from "@sb1/oauth.ts"
|
||||
import {
|
||||
BANK_INITIAL_REFRESH_TOKEN,
|
||||
BANK_OAUTH_CLIENT_ID,
|
||||
@ -5,22 +7,21 @@ import {
|
||||
DB_DIRECTORY,
|
||||
DB_FILENAME,
|
||||
} from "@/config.ts"
|
||||
import logger from "@common/logger.ts"
|
||||
import dayjs from "dayjs"
|
||||
import type { Database } from "better-sqlite3"
|
||||
import {
|
||||
clearTokens,
|
||||
createDb,
|
||||
fetchToken,
|
||||
insertTokens,
|
||||
} from "@sb1impl/db/queries.ts"
|
||||
import * as Oauth from "@sb1/oauth.ts"
|
||||
import * as Transactions from "@sb1/transactions.ts"
|
||||
import { bankTransactionIntoActualTransaction } from "./mappings.ts"
|
||||
import type { OAuthTokenResponse } from "@sb1/types.ts"
|
||||
import { createDirIfMissing } from "@/fs.ts"
|
||||
import logger from "@common/logger.ts"
|
||||
import dayjs from "dayjs"
|
||||
|
||||
import type { ActualTransaction, Bank, Interval } from "@common/types.ts"
|
||||
import type { TokenResponse } from "@sb1impl/db/types.ts"
|
||||
import { createDirIfMissing } from "@/fs.ts"
|
||||
import type { OAuthTokenResponse } from "@sb1/types.ts"
|
||||
import type { Database } from "better-sqlite3"
|
||||
|
||||
export class Sparebank1Impl implements Bank {
|
||||
private readonly db: Database
|
||||
@ -31,6 +32,7 @@ export class Sparebank1Impl implements Bank {
|
||||
this.db = createDb(databaseFilePath)
|
||||
}
|
||||
|
||||
// TODO if not cleared rerun later
|
||||
async fetchTransactions(
|
||||
interval: Interval,
|
||||
...accountKeys: ReadonlyArray<string>
|
||||
@ -40,8 +42,15 @@ export class Sparebank1Impl implements Bank {
|
||||
accountKeys,
|
||||
interval,
|
||||
)
|
||||
const sparebankTransactions = response.transactions
|
||||
return sparebankTransactions.map(bankTransactionIntoActualTransaction)
|
||||
|
||||
return response.transactions
|
||||
.map((transaction) => {
|
||||
const actualTransaction =
|
||||
bankTransactionIntoActualTransaction(transaction)
|
||||
|
||||
return actualTransaction.cleared === true ? actualTransaction : null
|
||||
})
|
||||
.filter((transaction) => transaction !== null)
|
||||
}
|
||||
|
||||
shutdown(): void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user