Relative from and to date in config, changed default to 3 days
All checks were successful
Deploy application / deploy (push) Successful in 7s

This commit is contained in:
2025-01-31 16:58:02 +01:00
parent 752bdbceb4
commit 18a0fbfac8
5 changed files with 30 additions and 6 deletions

View File

@ -1,4 +1,8 @@
import { BANK_INITIAL_REFRESH_TOKEN } from "@/../config.ts"
import {
BANK_INITIAL_REFRESH_TOKEN,
TRANSACTION_RELATIVE_FROM_DATE,
TRANSACTION_RELATIVE_TO_DATE,
} from "@/../config.ts"
import logger from "@/logger.ts"
import dayjs from "dayjs"
import { Database } from "better-sqlite3"
@ -66,7 +70,7 @@ export class Sparebank1Impl implements Bank {
private async getRefreshToken(): Promise<string> {
const tokenResponse = fetchToken(this.db, "refresh-token")
logger.debug(`Database returned refresh token: '%o'`, tokenResponse)
if (!tokenResponse) {
return BANK_INITIAL_REFRESH_TOKEN
} else if (this.isValidToken(tokenResponse)) {
@ -95,10 +99,11 @@ export class Sparebank1Impl implements Bank {
...accountKeys: ReadonlyArray<string>
): Promise<TransactionResponse> {
const today = dayjs()
const lastDay = today.subtract(1, "day")
const fromDate = today.subtract(TRANSACTION_RELATIVE_FROM_DATE, "days")
const toDate = today.subtract(TRANSACTION_RELATIVE_TO_DATE, "days")
return await Api.transactions(await this.getAccessToken(), accountKeys, {
fromDate: lastDay,
toDate: today,
fromDate,
toDate,
})
}
}

View File

@ -23,6 +23,8 @@ import { CronJob } from "cron"
// TODO move tsx to devDependency. Requires ts support for Node with support for @ alias
// TODO global exception handler, log and graceful shutdown
// TODO verbatimSyntax in tsconfig, conflicts with jest
// TODO multi module project. Main | DAL | Sparebank1 impl
// TODO store last fetched date in db, and refetch from that date, if app has been offline for some time
export async function daily(actual: Actual, bank: Bank): Promise<void> {
// Fetch transactions from the bank

View File

@ -17,7 +17,7 @@ export function bankTransactionIntoActualTransaction(
amount: transaction.amount * 100,
date: toISODateString(dayjs(transaction.date)),
payee_name: transaction.cleanedDescription,
// TODO if not cleared, rerun later
// TODO if not cleared or nonUniqueId is 0, rerun later
cleared: transaction.bookingStatus === "BOOKED",
}
}