Skip to content

Commit e8486e5

Browse files
committed
Enhance type safety by updating recalculateTargets response handling and defining RecalculateTargetsResponse type
1 parent f48bb22 commit e8486e5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

frontend/src/app/main/copilot/copilot-value-modeling/copilot-value-modeling.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, inject, OnInit } from '@angular/core';
22
import { MatTableModule } from '@angular/material/table';
33
import { Subject, takeUntil } from 'rxjs';
44
import { InstallationsService } from '../../../services/api/installations.service';
5-
import { Target, Targets, TargetsService } from '../../../services/api/targets.service';
5+
import { Target, Targets, TargetsService, RecalculateTargetsResponse } from '../../../services/api/targets.service';
66
import { MatIconModule } from '@angular/material/icon';
77
import { MatButtonModule } from '@angular/material/button';
88
import { MAT_DIALOG_DATA, MatDialog, MatDialogActions, MatDialogContent, MatDialogRef, MatDialogTitle } from '@angular/material/dialog';
@@ -150,8 +150,9 @@ export class CopilotValueModelingComponent implements OnInit {
150150

151151
resetTargets() {
152152
// Call the backend endpoint to recalculate targets
153-
this.targetsService.recalculateTargets().subscribe((result: any) => {
154-
const targets = result.targets || result; // handle both {targets, logs} and just targets
153+
this.targetsService.recalculateTargets().subscribe((result: RecalculateTargetsResponse) => {
154+
// Handle response format - could be {targets: Targets, logs?: any[]} or just Targets
155+
const targets = 'targets' in result ? result.targets : result as Targets;
155156
this.orgDataSource = this.transformTargets(targets.org);
156157
this.userDataSource = this.transformTargets(targets.user);
157158
this.impactDataSource = this.transformTargets(targets.impact);

frontend/src/app/services/api/targets.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export interface Targets {
3434
}
3535
}
3636

37+
export interface TargetsCalculationResponse {
38+
targets: Targets;
39+
logs?: any[]; // Optional calculation logs
40+
}
41+
42+
// Union type to handle both response formats
43+
export type RecalculateTargetsResponse = TargetsCalculationResponse | Targets;
44+
3745
@Injectable({
3846
providedIn: 'root'
3947
})
@@ -80,7 +88,7 @@ export class TargetsService {
8088

8189
recalculateTargets() {
8290
// Calls the backend endpoint to recalculate targets
83-
return this.http.get<any>(`${this.apiUrl}/calculate`);
91+
return this.http.get<RecalculateTargetsResponse>(`${this.apiUrl}/calculate`);
8492
}
8593
}
8694

0 commit comments

Comments
 (0)