diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c085f78..b41e339 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,5 @@ jobs: node-version: '18' - name: Install dependencies run: npm install - - name: Setup config.json file - run: cp src/server/config.template.json src/server/config.json - name: Run build run: npm run build diff --git a/package-lock.json b/package-lock.json index 6c8829a..6856a32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,9 @@ "jsdom": "^22.1.0", "rollup": "^3.28.0", "typescript": "^3.8.2" + }, + "engines": { + "node": "18" } }, "node_modules/@ampproject/remapping": { diff --git a/src/server/config.template.json b/src/server/config.template.json deleted file mode 100644 index e182cc3..0000000 --- a/src/server/config.template.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "accounts": {} -} diff --git a/src/server/config.ts b/src/server/config.ts index 1b46770..d7112ad 100644 --- a/src/server/config.ts +++ b/src/server/config.ts @@ -1,4 +1,3 @@ -import config from './config.json'; import { buildColumn } from './table-utils'; import { Transformers } from './transformers'; import type { Strategy, StrategyOption, Table } from './types'; @@ -31,7 +30,7 @@ export class Config { ], columnImportRules: { ref: null, - iban: (data) => new Array(data.length).fill(config?.accounts?.N26), + iban: (data) => new Array(data.length).fill(Utils.getBankIban('N26')), date: buildColumn(n26Cols.Date, (val) => new Date(val)), amount: buildColumn(n26Cols.Amount, parseFloat), category: buildColumn(n26Cols.Payee, Transformers.transformCategory), @@ -75,7 +74,7 @@ export class Config { columnImportRules: { ref: null, iban: (data) => - new Array(data.length).fill(config?.accounts?.OPENBANK), + new Array(data.length).fill(Utils.getBankIban('OPENBANK')), date: buildColumn(openbankCols.Fecha, (val) => { let [day, month, year] = val.split('/'); let yearNum = +year; diff --git a/src/server/utils.ts b/src/server/utils.ts index 39654cd..00d3cb3 100644 --- a/src/server/utils.ts +++ b/src/server/utils.ts @@ -1,4 +1,4 @@ -import { Table, InputColumn } from './types'; +import { Table, InputColumn, StrategyOption } from './types'; export const SOURCE_SHEET_ID = 1093484485; @@ -106,4 +106,31 @@ export class Utils { return data; }; } + + static getBankAccounts(): Record { + // this range contains the ibans only + const ibans = FireSpreadsheet.getRangeByName('accounts'); + // we also need to include the labels + const accounts = ibans + ?.offset(0, -1, ibans.getLastRow(), 2) + .getValues() + // make sure not to include empty rows + .filter((row) => row.some((cell) => cell !== '' && cell !== null)); + + if (!accounts?.length) { + return {}; // return empty list of bank accounts if none setup + } + + // convert the list to an object to easy work with it + return accounts.reduce((obj, account) => { + const [id, iban] = account; + obj[id.toUpperCase()] = iban; + return obj; + }, {}); + } + + static getBankIban(bank: string): string { + const bankAccounts = Utils.getBankAccounts(); + return bankAccounts?.[bank] ?? ''; + } }