import { Injectable } from '@angular/core' ; import { ApiCallService , ApiService , httpObserveOptions , HttpProtocolHelper } from '../../services/api-call.service' ; import { Observable } from 'rxjs' ; import { filter , map } from 'rxjs/operators' ; import { CmdbLog } from '../models/cmdb-log' ; import { CollectionParameters } from '../../services/models/api-parameter' ; import { APIGetMultiResponse } from '../../services/models/api-response' ; import { HttpParams , HttpResponse } from '@angular/common/http' ; @ Injectable ( { providedIn : 'root' } ) export class LogService < T = CmdbLog > implements ApiService { constructor ( private api ) { } public servicePrefix : string = 'log' ; public getLog ( publicID ) { return this . api . callGet < T > ( `${ this . servicePrefix }/${ publicID }` ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } param publicID param params public getLogsByObject ( publicID , params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const options = HttpProtocolHelper . createHttpProtocolOptions ( httpObserveOptions , JSON . stringify ( params . filter ) , params . limit , params . sort , params . order , params . page ) ; return this . api . callGet < Array < T > > ( `${ this . servicePrefix }/object/${ publicID }` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } public getLogsWithExistingObject ( params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const options = HttpProtocolHelper . createHttpProtocolOptions ( httpObserveOptions , params . filter , params . limit , params . sort , params . order , params . page ) ; return this . api . callGet < Array < T > > ( `${ this . servicePrefix }/object/exists` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } public getLogsWithNotExistingObject ( params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const options = HttpProtocolHelper . createHttpProtocolOptions ( httpObserveOptions , params . filter , params . limit , params . sort , params . order , params . page ) ; return this . api . callGet < T > ( `${ this . servicePrefix }/object/notexists` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } public getDeleteLogs ( params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const options = HttpProtocolHelper . createHttpProtocolOptions ( httpObserveOptions , params . filter , params . limit , params . sort , params . order , params . page ) ; return this . api . callGet < T > ( `${ this . servicePrefix }/object/deleted` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } public getCorrespondingLogs ( publicID ) { return this . api . callGet < T > ( `${ this . servicePrefix }/${ publicID }/corresponding` ) . pipe ( map ( ( apiResponse ) => { if ( apiResponse . status === 204 ) { return [ ] ; } return apiResponse . body ; } ) ) ; } public deleteLog ( publicID ) { return this . api . callDelete < boolean > ( `${ this . servicePrefix }/${ publicID }` ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } }