Skip to content

Commit

Permalink
Remove transactions (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
errietta committed Oct 7, 2018
1 parent c49d9bb commit b57276c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/lib/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Report {
resetFilter(): void;

addTransactions(transactions: Transaction[]): void;
removeTransactions(transactionIds: string[]): void;
};

class ReportImpl implements Report {
Expand Down Expand Up @@ -59,6 +60,13 @@ class ReportImpl implements Report {
this.transactions = this.unfilteredTransactions.filter(txn => txn.calculatedMonth === this.reportFilter.month);
}
}

removeTransactions(transactionsToRemove: string[]) {
this.unfilteredTransactions = this.unfilteredTransactions.filter(txn => (
transactionsToRemove.indexOf(txn.identifier) === -1
));
this.applyFilter();
}
}

export class ReportFactory {
Expand Down Expand Up @@ -103,6 +111,10 @@ export class ReportFactory {

return new Promise((resolve, reject) => resolve());
}

removeRecords(transactionIdentifiers: string[]) {
this.report.removeTransactions(transactionIdentifiers);
}
}

export default ReportFactory;
4 changes: 3 additions & 1 deletion src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export class Transaction {
this.calculatedMonth = this.calendarMonth;
}

this.identifier = this.build_identifier();
if (!this.identifier) {
this.identifier = this.build_identifier();
}
}

txn_amount() {
Expand Down
23 changes: 23 additions & 0 deletions test/report.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,27 @@ describe('ReportFactory', () => {
expect(report.transactions[5].creditAmount).to.equal(0);
});
});
it ('can remove transactions', () => {
let rf = new ReportFactory();
return rf.addRecords([{
date: '2018-01-01',
identifier: 'a1',
}, {
date: '2018-01-01',
identifier: 'a2',
}, {
date: '2018-01-03',
identifier: 'a3',
}, {
date: '2018-01-04',
identifier: 'a4',
}])
.then(() => {
rf.removeRecords(['a2','a3','b'])
})
.then(() => {
expect(rf.report.transactions.map(t => t.identifier))
.to.deep.equal(['a1','a4'])
})
})
});

0 comments on commit b57276c

Please sign in to comment.