import {Injectable,Inject} from '@angular/core'; import { HttpClient,HttpResponse} from '@angular/Common/http'; import { Observable, Subject } from "rxjs"; import { DyCommon } from '../Common'; @Injectable() export class ObjectService { private http: HttpClient; private ngUnsubscribe: Subject = new Subject(); ngOnDestroy(): any { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } constructor(@Inject(HttpClient) Http: HttpClient) { this.http = Http; } public saveObject = (objectName, object): Observable => { return this.http.post(`/api/objects/${objectName}/`, JSON.stringify(object)).takeUntil(this.ngUnsubscribe).catch((err,caught) => Observable.throw( DyCommon.LogError(err)),); } public deleteObject = (objectName, object): Observable => { return this.http.delete(`/api/objects/${objectName}/${object.id}`).takeUntil(this.ngUnsubscribe).catch((err, caught) => Observable.throw(DyCommon.LogError(err))); } public getObject = (objectName, objectId): Observable => { return this.http.get(`/api/objects/${objectName}/${objectId}`).takeUntil(this.ngUnsubscribe).catch((err, caught) => Observable.throw(DyCommon.LogError(err))); } }