Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/dist
/dist
*.log
52 changes: 52 additions & 0 deletions data/DodgyTransactions2015.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Date,From,To,Narrative,Amount
01/01/2015,Laura B,Sarah T,Misc Morale,10.54
04/01/2015,Stephen S,Gergana I,Lunch,3.22
07/01/2015,Ben B,Jon A,Fantasy Football,9.93
11/01/2015,Ben B,Todd,Lunch,7.33
12/01/2015,Laura B,Ben B,Beers,8.94
15/01/2015,Todd,Rob S,Beers,10.19
16/01/2015,Laura B,Jon A,Lego Assistance,0.69
18/01/2015,Jon A,Sarah T,Coffee,10.73
22/01/2015,Gergana I,Todd,Coffee,0.8
24/01/2015,Gergana I,Chris W,Coffee,8.49
27/01/2015,Laura B,Tim L,Jenkins Fees,0.52
29/01/2015,Sam N,Chris W,Lunch,9.01
01/02/2015,Stephen S,Laura B,Coffee,7.53
02/02/2015,Stephen S,Rob S,Fantasy Football,7.43
04/02/2015,Rob S,Stephen S,Fantasy Football,5.78
06/02/2015,Dan W,Gergana I,Automated Testing Services,10.29
07/02/2015,Jon A,Chris W,Rails Consultancy,7.37
10/02/2015,Sam N,Gergana I,Sandbox Help,9.84
11/02/2015,Chris W,Stephen S,Misc Morale,0.68
13/02/2015,Laura B,Gergana I,Beers,6.56
16/02/2015,Chris W,Dan W,Jenkins Fees,1.28
17/02/2015,Sarah T,Dan W,Sandbox Help,11.48
18/02/2015,Stephen S,Rob S,Lego Assistance,4.83
21/02/2015,Dan W,Ben B,Pokemon Training,0.5
24/02/2015,Todd,Gergana I,Coffee,9.08
26/02/2015,Stephen S,Jon A,Pokemon Training,4.23
01/03/2015,Ben B,Sam N,Lunch,One Cheeseburger
02/03/2015,Todd,Chris W,Sandbox Help,1.92
04/03/2015,Laura B,Jon A,Sandcastle Help,9.09
06/03/2015,Stephen S,Gergana I,Lego Assistance,9.4
08/03/2015,Ben B,Sam N,Pokemon Training,11.32
11/03/2015,Stephen S,Jon A,Sandcastle Help,11.57
15/03/2015,Todd,Sam N,Pokemon Training,2.29
19/03/2015,Laura B,Chris W,Coffee,9.96
21/03/2015,Jon A,Gergana I,Beers,7.54
25/03/2015,Gergana I,Ben B,Automated Testing Services,2.39
28/03/2015,Stephen S,Tim L,Lunch,5.83
29/03/2015,Gergana I,Ben B,Audit and Other Financial Services,10.85
30/03/2015,Tim L,Todd,Pokemon Training,8.6
02/04/2015,Stephen S,Chris W,Pokemon Training,1.11
05/04/2015,Chris W,Ben B,Lunch,0.96
09/04/2015,Chris W,Rob S,Audit and Other Financial Services,11.79
12/04/2015,Gergana I,Laura B,Stationary Items,8.37
13/04/2015,Laura B,Tim L,Services Rendered,1.27
15/04/2015,Ben B,Sam N,Lego Assistance,8.5
19/04/2015,Stephen S,Chris W,White Water Rafting,8.91
23/04/2015,Tim L,Todd,Misc Morale,8.1
24/04/2015,Tim L,Sarah T,Arcade Social,6.38
26/04/2015,Jon A,Todd,Stationary Items,8.44
27/04/2015,Ben B,Jon A,Pokemon Training,10.91
Last Thursday,Sarah T,Dan W,Beers,5.42
22 changes: 22 additions & 0 deletions import/csvService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readFileSync } from "fs";
import { parse } from "csv-parse/sync";
import type { TransactionRecord } from "../types/transactionRecord";
import type { FileDataRecord } from "../types/fileDataRecord";
import { getParsedObjectsToTransactionRecords } from "../utils/parseObjectToTransactionRecord";

const HEADERS = ["Date", "From", "To", "Narrative", "Amount"];

export const csvService = (filePath: string): TransactionRecord[] => {
const fileContent = readFileSync(filePath, { encoding: "utf-8" });

const records = parse(fileContent, {
delimiter: ",",
columns: HEADERS,
from_line: 2,
});

let transactionRecords: TransactionRecord[] =
getParsedObjectsToTransactionRecords(records as FileDataRecord[]);

return transactionRecords;
};
9 changes: 6 additions & 3 deletions interface/menu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountManager } from "../account/accountManager";
import { getTransactionData } from "../utils/getTransactionData";
import { csvService } from "../import/csvService";
import { convertPenceToPounds } from "../utils/penceConverter";
import { getUserInput } from "../utils/getUserInput";
import type { TransactionRecord } from "../types/transactionRecord";
Expand Down Expand Up @@ -83,8 +83,11 @@ export class Menu {
};

#loadTransactionRecords = () => {
const transactionRecords = getTransactionData(
"./data/Transactions2014.csv",
// const transactionRecords = getTransactionData(
// "./data/Transactions2014.csv",
// );
const transactionRecords = csvService(
"./data/DodgyTransactions2015.csv",
);
transactionRecords.forEach((record) => {
this.accountManager.addTransactionRecord(record);
Expand Down
113 changes: 113 additions & 0 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
},
"license": "ISC",
"author": "",
"type": "module",
"type": "commonjs",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting - how come you've made this change?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log4js had a couple of dependencies which required commonjs to compile. It might be worth finding another library which is supported without changing to commonjs - this was just a quick solution.

"main": "index.ts",
"scripts": {
"start": "tsc && esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/bundle.js && node dist/bundle.js",
"start": "tsc && esbuild index.ts --bundle --format=cjs --platform=node --outfile=dist/bundle.js && node dist/bundle.js",
"test": "echo \"Error: no test specified\" && exit 1",
"format": "prettier . --write"
},
Expand All @@ -29,6 +29,7 @@
"dependencies": {
"csv-parse": "^6.1.0",
"date-fns": "^4.1.0",
"log4js": "^6.9.1",
"lodash": "^4.17.21",
"ts-node": "^10.9.2"
}
Expand Down
7 changes: 7 additions & 0 deletions types/fileDataRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface FileDataRecord {
Date: string;
From: string;
To: string;
Narrative: string;
Amount: string;
}
52 changes: 0 additions & 52 deletions utils/getTransactionData.ts

This file was deleted.

18 changes: 18 additions & 0 deletions utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { configure } from "log4js";

var loggerConfiguration = configure({
appenders: {
file: { type: "file", filename: "logs.log" },
out: { type: "stdout" },
},
categories: {
default: { appenders: ["file", "out"], level: "error" },
},
})

export function getLogger(filename: string): ReturnType<typeof loggerConfiguration.getLogger>
{
const logger = loggerConfiguration.getLogger(filename);
logger.level = "debug";
return logger;
}
Loading