Я не могу обновить или удалить запись, используя следующий код:
Услуги
UpdateWeatherData (вес: Погода) {
вернуть this.http.put (/WeatherModels/Update
, вес);
}
DeleteWeatherData(wt : Weather){
return this.http.delete(`/WeatherModelsDelete/`+wt);
}
if(request.url.endsWith('/WeatherModels/Update') && request.method === 'PUT'){
// check for fake auth token in header and return user if valid, this security is implemented server side in a real application
if(request.headers.get('Authorization')=== 'Bearer xyz@123'){
// find items by id in weather data array
//let urlParts = request.url.split('/');
//let id = parseInt(urlParts[urlParts.length-1]);
let WeatherModel = request.body;
let id = WeatherModel.ID;
for(let i=0;i < WeatherModels.length;i++){
// let WeatherModel = WeatherModels[i];
if(id === WeatherModels[i].ID){
WeatherModels[i]. (WeatherModel);
localStorage.setItem('WeatherModels',JSON.stringify(WeatherModels));
break;
}
}
return of(new HttpResponse({ status : 200}));
} else{
return throwError({ error: { message : 'Unauthorised'} } );
}
}
here not able to reach the below url
if (request.url.match(/\/WeatherModelsDelete\/\d+$/) && request.method === 'DELETE') {
if(request.headers.get('Authorization')=== 'Bearer xyz@123'){
let WeatherModel = request.body;
let id = WeatherModel.ID;
for(let i=0;i < WeatherModels.length;i++){
let WeatherModel = WeatherModels[i];
if(WeatherModel[i].ID===id){
//update the collection
WeatherModels.splice(i,1);
localStorage.setItem('WeatherModels',JSON.stringify(WeatherModels));
break;
}
}
return of(new HttpResponse({ status : 200}));
} else{
return throwError({ error: { message : 'Unauthorised'} } );
}
}