import { Injectable } from '@angular/core' ; import { ApiCallService , ApiService , resp } from '../../../services/api-call.service' ; import { UserSetting , UserSettingPayload } from '../models/user-setting' ; import { AuthService } from '../../../auth/services/auth.service' ; import { User } from '../../models/user' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { HttpHeaders , HttpParams , HttpResponse } from '@angular/common/http' ; import { APIDeleteSingleResponse , APIGetListResponse , APIGetSingleResponse , APIInsertSingleResponse , APIUpdateSingleResponse } from '../../../services/models/api-response' ; export function convertResourceURL ( url ) { return url . substring ( 1 ) . split ( '/' ) . join ( '-' ) ; } /**
 * Service class for API user settings.
 */ @ Injectable ( { providedIn : 'root' } ) export class UserSettingsService < T = UserSetting , P = UserSettingPayload > implements ApiService { /**
     * Default REST URL Prefix.
     */ public servicePrefix : string ; /**
     * The current login user.
     */ public currentUser : User ; public currentUserObservable : Observable < User > ; public readonly options = { headers : new HttpHeaders ( { 'Content-Type' : 'application/json' } ) , params : { } , observe : resp } ; param api param authService constructor ( private api , private authService ) { this . currentUserObservable = this . authService . currentUser ; this . currentUserObservable . subscribe ( ( user ) => { this . currentUser = user ; this . servicePrefix = `users/${ this . authService . currentUserValue . public_id }/settings` ; } ) ; } param resource param payloads public createUserSetting < PAYLOAD > ( resource , payloads ) { return new UserSetting < PAYLOAD > ( resource , this . currentUser . public_id , payloads ) ; } /**
     * Get all settings from the logged user.
     */ public getUserSettings ( ) { const options = this . options ; options . params = new HttpParams ( ) ; return this . api . callGet < T > ( `users/${ this . authService . currentUserValue . public_id }/settings/` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body . results as Array < T > ; } ) ) ; } param identifier public getUserSetting ( identifier ) { const options = this . options ; options . params = new HttpParams ( ) ; return this . api . callGet < T > ( `users/${ this . authService . currentUserValue . public_id }/settings/${ identifier }/` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body . result as T ; } ) ) ; } param setting public addUserSetting ( setting ) { const options = this . options ; options . params = new HttpParams ( ) ; return this . api . callPost < T > ( `users/${ this . authService . currentUserValue . public_id }/settings/` , setting , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body . raw as T ; } ) ) ; } param identifier param setting public updateUserSetting ( identifier , setting ) { const options = this . options ; options . params = new HttpParams ( ) ; return this . api . callPut < T > ( `users/${ this . authService . currentUserValue . public_id }/settings/${ identifier }` , setting , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body . result as T ; } ) ) ; } param identifier public deleteUserSetting ( identifier ) { const options = this . options ; options . params = new HttpParams ( ) ; return this . api . callDelete < T > ( `users/${ this . authService . currentUserValue . public_id }/settings/${ identifier }` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body . raw as T ; } ) ) ; } }