I am trying to use the PUT Method and I am keeping this issue
http://localhost:4200/api/v1/assegnazione-progetto/13 400 (Bad Request)
Can you look at the code?
--- PROGETTI-ASSEGNAZIONE.SERVICE.TS ---
// PUT
updateAssegnazioneProgettoById(
risorsaId: number,
updatedData: AssegnazioneRisorsaProgettoDTO
): Observable<AssegnazioneRisorsaProgettoDTO> {
return this.http.put<AssegnazioneRisorsaProgettoDTO>(
`/api/v1/assegnazione-progetto/${risorsaId}`,
updatedData
);
}
--- PROGETTI-ASSEGNA-FORM.HTML ---
<app-button
text="Modifica"
btnClass="btn btn-edit"
type="button"
(click)="editAssegnazione(progettoId)"
></app-button>
--- PROGETTI-ASSEGNA-FORM.TS ---
editAssegnazione(id: number) {
if (this.assegnaProgettoForm.valid) {
const formValue = this.assegnaProgettoForm.value;
// Construct the update data object
const updateData: AssegnazioneRisorsaProgettoDTO = {
progettoId: id,
risorsaId: formValue.risorsaId,
nomeProgetto: formValue.nomeProgetto,
dataInizioAssegnazione: new Date(formValue.dataInizio),
dataFineAssegnazione: new Date(formValue.dataFine),
ore: parseInt(formValue.ore, 10),
};
console.log('This is the progetto ID:', this.progettoId);
this.progettiAssegnazioneService
.updateAssegnazioneProgettoById(id, updateData)
.subscribe({
next: (response) => {
console.log('Update successful', response);
},
error: (error) => {
console.error('Error updating', error);
},
complete: () => {
console.log('Update operation completed');
},
});
} else {
console.error('Form is invalid');
}
}