I want to update part of data through an API. I've successfully made a POST data. I would also like to do PATCH to update one field of the data.
Below is the code am trying to use for the changes:
else if (out_timing.worker_timeout_id === emp_id && out_timing.check_status === false) {
let checkOutTime = new TimeOutModel(out_timing.date, emp_id, out_timing.time_out, true);
//introduced two lines below to carry out update for last field
let updateCheckStatus = new TimeInModel("", "", "", false);
this.employeesService.patchTimeinStatus(updateCheckStatus)
this.employeesService.pushTimeOut(checkOutTime)
.subscribe(checkOutTime => {
},
error => this.errorMessage = <any>error);
console.log("Successfully checked-out!");
break;
}
else {
console.log("All conditions exhausted!");
break;
}
This is what I have in my service component.
patchTimeinStatus(timing: TimeInModel): Observable<TimeInModel> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.patch(this.empApiUrl + '/time-in/', timing, options)
.map(this.extractData)
.catch(this.handleErrorObservable);
}
I get 405 method not allowed from the server. Apart from that, I doubt whether what am doing is correct. What is the correct approach to do the update using patch or put methods?