-
Notifications
You must be signed in to change notification settings - Fork 0
/
regular-expenses.component.ts
34 lines (30 loc) · 1.1 KB
/
regular-expenses.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Component, Input } from '@angular/core';
import { Transaction } from 'src/app/models/transaction.interface';
import { DataService } from '../../services/data.service';
import { Account } from '../../models/account.interface';
import { User } from '../../models/user.interface';
@Component({
selector: 'app-regular-expenses',
templateUrl: './regular-expenses.component.html',
styleUrls: ['./regular-expenses.component.css'],
})
export class RegularExpensesComponent {
private user: User = {} as User;
private account: Account = {} as Account;
regularTransactions: Transaction[] = [];
constructor(dataService: DataService) {
this.user = dataService.getUser();
this.account = dataService.getAccount();
const transactionCounts: { [key: string]: number } = {};
this.account.transactions.forEach((t) => {
if (transactionCounts[t.location]) {
transactionCounts[t.location]++;
} else {
transactionCounts[t.location] = 1;
}
});
this.regularTransactions = this.account.transactions.filter(
(t) => transactionCounts[t.location] > 2
);
}
}