Skip to content

Commit

Permalink
Remove the need of configuration file, accounts are extracted directl…
Browse files Browse the repository at this point in the history
…y from the spreadsheet (#19)
  • Loading branch information
melledijkstra authored Nov 12, 2023
1 parent 836b729 commit 9cc285a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/server/config.template.json

This file was deleted.

5 changes: 2 additions & 3 deletions src/server/config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion src/server/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Table, InputColumn } from './types';
import { Table, InputColumn, StrategyOption } from './types';

export const SOURCE_SHEET_ID = 1093484485;

Expand Down Expand Up @@ -106,4 +106,31 @@ export class Utils {
return data;
};
}

static getBankAccounts(): Record<string, string> {
// 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] ?? '';
}
}

0 comments on commit 9cc285a

Please sign in to comment.