diff --git a/package.json b/package.json index 83558ba..e9087b1 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "start-prod": "node --import=tsx ./src/main.ts", "run-once": "ONCE=true dotenvx run --env-file=.env.local -- node --import=tsx ./src/main.ts | pino-pretty", "test": "dotenvx run --env-file=.env.test.local -- node --experimental-vm-modules node_modules/jest/bin/jest.js | pino-pretty", + "docker-build": "DB_DIRECTORY=data docker compose --env-file .env.local up -d --build", "format": "prettier --write \"./**/*.{js,mjs,ts,md,json}\"" }, "keywords": [], diff --git a/src/bank/sparebank1.ts b/src/bank/sparebank1.ts index 84b9243..3e64eea 100644 --- a/src/bank/sparebank1.ts +++ b/src/bank/sparebank1.ts @@ -18,6 +18,8 @@ export interface OAuthTokenResponse { refresh_token: string } +export type BookingStatus = "PENDING" | "BOOKED" + export interface Transaction { id: string nonUniqueId: string @@ -25,6 +27,7 @@ export interface Transaction { amount: number // Amount in NOK cleanedDescription: string remoteAccountName: string + bookingStatus: BookingStatus [key: string]: string | number | boolean | unknown } @@ -33,15 +36,13 @@ export interface TransactionResponse { transactions: ReadonlyArray } -export type Bank = Sparebank1 - -export interface Sparebank1 { +export interface Bank { transactionsPastDay: ( ...accountKeys: ReadonlyArray ) => Promise } -export class Sparebank1Impl implements Sparebank1 { +export class Sparebank1Impl implements Bank { private readonly db: Database constructor(db: Database) { @@ -93,7 +94,6 @@ export class Sparebank1Impl implements Sparebank1 { async transactionsPastDay( ...accountKeys: ReadonlyArray ): Promise { - // TODO API is inclusive, today should equal lastDay const today = dayjs() const lastDay = today.subtract(1, "day") return await Api.transactions(await this.getAccessToken(), accountKeys, { diff --git a/src/main.ts b/src/main.ts index 18d472c..a151190 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,10 +36,10 @@ export async function daily(actual: Actual, bank: Bank): Promise { bankTransactionIntoActualTransaction(transaction, accountId), ) - logger.trace({ + logger.debug({ aMessage: "Mapped from Bank to Actual", - from: JSON.stringify(transactions), - to: JSON.stringify(actualTransactions), + from: transactions, + to: actualTransactions, }) // TODO Import transactions into Actual @@ -92,6 +92,7 @@ async function main(): Promise { } logger.info("Waiting for CRON job to start") + // TODO init and shutdown resources when job runs? cronJob = cronJobDaily(async () => await daily(actual, bank)) async function shutdown(): Promise { diff --git a/src/mappings.ts b/src/mappings.ts index a3126dd..5cf3def 100644 --- a/src/mappings.ts +++ b/src/mappings.ts @@ -17,6 +17,8 @@ export function bankTransactionIntoActualTransaction( amount: transaction.amount * 100, date: toISODateString(dayjs(transaction.date)), payee_name: transaction.cleanedDescription, + // TODO if not cleared, rerun later + cleared: transaction.bookingStatus === "BOOKED", } } diff --git a/tests/stubs/bankStub.ts b/tests/stubs/bankStub.ts index 85539d3..847e135 100644 --- a/tests/stubs/bankStub.ts +++ b/tests/stubs/bankStub.ts @@ -1,4 +1,8 @@ -import type { Bank, TransactionResponse } from "@/bank/sparebank1.ts" +import type { + Bank, + BookingStatus, + TransactionResponse, +} from "@/bank/sparebank1.ts" import dayjs from "dayjs" export class BankStub implements Bank { @@ -9,6 +13,7 @@ export class BankStub implements Bank { date: dayjs("2019-08-20").unix(), cleanedDescription: "Test transaction", remoteAccountName: "Test account", + bookingStatus: "BOOKED" as BookingStatus, } return { transactions: [