import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { ApiCallService , ApiService , httpObserveOptions } from '../../services/api-call.service' ; import { CmdbLink } from '../models/cmdb-link' ; import { HttpParams , HttpResponse } from '@angular/common/http' ; import { APIDeleteSingleResponse , APIGetMultiResponse , APIGetSingleResponse , APIInsertSingleResponse } from '../../services/models/api-response' ; import { CollectionParameters } from '../../services/models/api-parameter' ; @ Injectable ( { providedIn : 'root' } ) export class LinkService < T = CmdbLink > implements ApiService { public servicePrefix : string = 'objects/links' ; constructor ( private api ) { } param publicID public getLink ( publicID ) { const options = httpObserveOptions ; options . params = new HttpParams ( ) ; return this . api . callGet < T > ( `${ this . servicePrefix }/${ publicID }` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body . result as T ; } ) ) ; } param objectID param link public getPartnerID ( objectID , link ) { return objectID === link . primary ? link . secondary : link . primary ; } param params public getLinks ( params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const options = httpObserveOptions ; let httpParams = new HttpParams ( ) ; if ( params . filter !== undefined ) { const filter = JSON . stringify ( params . filter ) ; httpParams = httpParams . set ( 'filter' , filter ) ; } httpParams = httpParams . set ( 'limit' , params . limit . toString ( ) ) ; httpParams = httpParams . set ( 'sort' , params . sort ) ; httpParams = httpParams . set ( 'order' , params . order . toString ( ) ) ; httpParams = httpParams . set ( 'page' , params . page . toString ( ) ) ; options . params = httpParams ; return this . api . callGet < Array < T > > ( this . servicePrefix + '/' , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } param objectID param params public getPartnerLinks ( objectID , params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const options = httpObserveOptions ; let httpParams = new HttpParams ( ) ; const filter = JSON . stringify ( { $or : [ { primary : objectID } , { secondary : objectID } ] } ) ; httpParams = httpParams . set ( 'filter' , filter ) ; httpParams = httpParams . set ( 'limit' , params . limit . toString ( ) ) ; httpParams = httpParams . set ( 'sort' , params . sort ) ; httpParams = httpParams . set ( 'order' , params . order . toString ( ) ) ; httpParams = httpParams . set ( 'page' , params . page . toString ( ) ) ; options . params = httpParams ; return this . api . callGet < Array < T > > ( this . servicePrefix + '/' , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } param data public postLink ( data ) { const options = httpObserveOptions ; options . params = new HttpParams ( ) ; return this . api . callPost < CmdbLink > ( `${ this . servicePrefix }/` , data , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body . raw as T ; } ) ) ; } param publicID public deleteLink ( publicID ) { const options = httpObserveOptions ; options . params = new HttpParams ( ) ; return this . api . callDelete < number > ( `${ this . servicePrefix }/${ publicID }` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } }