Skip to content

Commit 9e2718a

Browse files
feat: Update cost fetching to use listActive and add logging for fetched costs
1 parent 2a9b327 commit 9e2718a

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/app/components/financial-impact-card/financial-impact-card.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class FinancialImpactCardComponent implements OnInit {
6767
if (this.usageCosts && this.usageCosts.length > 0) {
6868
this.costs.set(this.usageCosts);
6969
} else {
70-
this.costService.list().then((costs) => {
70+
this.costService.listActive().then((costs) => {
7171
this.costs.set(costs as CostDto[]);
7272
this.calculateAll();
7373
});

src/app/pages/financial-impact/financial-impact.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class FinancialImpactComponent implements OnInit {
4343
ngOnInit() {
4444
// Fetch all costs from the cost table
4545
this.costService.listActive().then((costs) => {
46+
console.log("Costs fetched:", costs);
4647
this.costs.set(costs);
4748
this.updateSpendingTrendChart(costs as CostDto[]);
4849
});

src/app/services/cost.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type Costs = CostDto | CostAddDto;
1717
providedIn: 'root'
1818
})
1919
export class CostService extends ServiceAbstract<Costs> {
20+
protected override dbService = inject(DbService);
21+
protected override dataUpdatedService = inject(DataUpdatedService);
22+
private substanceService = inject(SubstanceService);
23+
2024
protected override storeName = 'cost' as const;
2125

2226
/**
@@ -38,11 +42,10 @@ export class CostService extends ServiceAbstract<Costs> {
3842
]);
3943

4044
const activeSubstanceIds = activeSubstances.map(substance => substance.id);
41-
console.log("activeSubstanceIds", activeSubstanceIds);
42-
console.log("allCosts", allCosts);
43-
return (allCosts as CostDto[]).filter(cost =>
45+
const _return = (allCosts as CostDto[]).filter(cost =>
4446
activeSubstanceIds.includes(cost.substance)
4547
);
48+
return _return;
4649
}
4750

4851
/**
@@ -65,7 +68,8 @@ export class CostService extends ServiceAbstract<Costs> {
6568
* Returns the total spent across all costs.
6669
*/
6770
getTotalSpent() {
68-
return this.table.toArray().then(data => {
71+
//return this.table.toArray().then(data => {
72+
return this.listActive().then(data => {
6973
return data.reduce((acc, item) => {
7074
return acc + item.value;
7175
}, 0);

0 commit comments

Comments
 (0)