import { Observable } from 'rxjs'; import { AuthHttp } from 'angular2-jwt'; import { OrganizationSettings } from './organization-settings.model'; import { ApiPathComponent } from '../api-path-component'; import { IErrorHandler } from '../error/error-handler.interface'; import { OrganizationSettingsSerializer } from './organization-settings.serializer'; export class OrganizationSettingsService { public constructor( private baseUrl: string, private authHttp: AuthHttp, private serializer: OrganizationSettingsSerializer, private errorHandler: IErrorHandler ) { } public getOne(organizationId: string): Observable { const url: string = this.baseUrl + '/' + ApiPathComponent.organizations + '/' + organizationId + '/' + ApiPathComponent.settings; return this.authHttp.get(url) .catch((error?: any) => this.errorHandler.handle(error)) .map((res: Response) => this.serializer.deserialize(res.json())); } public update(organizationId: string, organizationSetting: OrganizationSettings): Observable { const url: string = this.baseUrl + '/' + ApiPathComponent.organizations + '/' + organizationId + '/' + ApiPathComponent.settings; return this.authHttp.put(url, this.serializer.serialize(organizationSetting)) .catch((error?: any) => this.errorHandler.handle(error)) .map((res: Response) => this.serializer.deserialize(res.json())); } }