My project utilizes on-premise servers, with the backend running on .NET Core. Since I develop on a Mac and cannot run an instance of our backend, I have created a separate (angular-cli) environment for my project that uses the in-memory-web-api.
Although I have successfully set it up to work for get/ and get/:id requests, I am facing issues with making delete requests. Is there a way to make this work with the in-memory-web-api or is it not feasible?
The Service
public getOperations(): Observable<IOperation[]>{
return this.http.get(`${environment.baseUrl}operations/`)
.map(this.sharedService.extractData)
.catch(this.sharedService.handleError);
}
public getOperation(operationId: string):Observable<IOperation>{
return this.http.get(`${environment.baseUrl}operations/${operationId}`)
.map(this.sharedService.extractData)
.catch(this.sharedService.handleError);
}
public deleteOperation(operationId: string): Observable<any>{
return this.http.delete(`${environment.baseUrl}operations/${operationId}`)
.map(this.sharedService.extractData)
.catch(this.sharedService.handleError);
}
The In memory database
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let operations: IOperation[] = [
new Operation({
id:'001',
name: 'Operation ABC',
status:'Active',
startDate: new Date().toLocaleDateString()
}),
new Operation({
id:'002',
name: 'Operation DEF',
status:'Closed',
startDate: new Date().toLocaleDateString(),
endDate: new Date().toLocaleDateString()
}),
new Operation({
id:'003',
name: 'Operation GHI',
status:'Closed',
startDate: new Date().toLocaleDateString(),
endDate: new Date().toLocaleDateString()
}),
new Operation({
id:'004',
name: 'Operation JKL',
status:'Closed',
startDate: new Date().toLocaleDateString(),
endDate: new Date().toLocaleDateString()
}),
];
return {operations};
}
}
I forgot to include my component method that calls the service method:
public deleteOperation(operation: IOperation){
this.confirmationService.confirm({
message: `Are you sure you want to delete '${operation.name}'?`,
accept: () => {
this.operationsService.deleteOperation(operation.id)
.subscribe(()=>{
this.loadOperations();
})
}
});
}