Skip to content

Commit

Permalink
fix bug with id of objective already being defined when trying to dup…
Browse files Browse the repository at this point in the history
…licate
  • Loading branch information
nevio18324 committed Nov 26, 2024
1 parent 2cd4d54 commit 2096cb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 8 additions & 2 deletions frontend/src/app/services/objective.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export class ObjectiveService {
return this.httpClient.delete<Objective>(`/api/v2/objectives/${objectiveId}`);
}

duplicateObjective(objectiveId: number, objectiveDTO: any): Observable<Objective> {
return this.httpClient.post<Objective>(`/api/v2/objectives/${objectiveId}`, objectiveDTO);
duplicateObjective(
objectiveId: number,
duplicateObjectiveDto: {
objective: Objective;
keyResults: KeyResult[];
},
): Observable<Objective> {
return this.httpClient.post<Objective>(`/api/v2/objectives/${objectiveId}`, duplicateObjectiveDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export class ObjectiveFormComponent implements OnInit, OnDestroy {
const value = this.objectiveForm.getRawValue();
const state = this.data.objective.objectiveId == null ? submitType : this.state;
let objectiveDTO: Objective = {
id: this.data.objective.objectiveId,
version: this.version,
quarterId: value.quarter,
description: value.description,
Expand All @@ -80,15 +79,13 @@ export class ObjectiveFormComponent implements OnInit, OnDestroy {
state: state,
} as unknown as Objective;

const submitFunction = this.getSubmitFunction(objectiveDTO.id, objectiveDTO);
const submitFunction = this.getSubmitFunction(this.data.objective.objectiveId!, {
objective: objectiveDTO,
keyResults: this.keyResults
.filter((keyResult, index) => value.keyResults[index])
.map((result) => ({ ...result, id: undefined })),
});
submitFunction.subscribe((savedObjective: Objective) => {
this.objectiveForm.getRawValue().keyResults.forEach((selected: boolean | null, index: number) => {
if (selected) {
this.keyResults[index].objective = savedObjective;
this.keyResultService.saveKeyResult(this.keyResults[index]).subscribe();
}
});

this.closeDialog(savedObjective, false, value.createKeyResults!);
});
}
Expand Down

0 comments on commit 2096cb7

Please sign in to comment.