import { Injectable } from '@angular/core' ; import { ApiCallService , ApiService , httpObserveOptions , resp } from '../../services/api-call.service' ; import { ExportdJob } from '../models/exportd-job' ; import { map } from 'rxjs/operators' ; import { Observable } from 'rxjs' ; import { CollectionParameters } from '../../services/models/api-parameter' ; import { APIGetMultiResponse } from '../../services/models/api-response' ; import { HttpHeaders , HttpParams , HttpResponse } from '@angular/common/http' ; @ Injectable ( { providedIn : 'root' } ) export class ExportdJobLogService < T = any > implements ApiService { public servicePrefix : string = 'exportdlog' ; public newServicePrefix : string = 'exportd/logs' ; public readonly options = { headers : new HttpHeaders ( { 'Content-Type' : 'application/json' } ) , params : { } , observe : resp } ; constructor ( private api ) { } param params public getLogs ( 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 . newServicePrefix , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } public getLogsWithExistingJobs ( params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const query = [ { $match : { log_type : 'ExportdJobLog' } } , { $match : { action : { $ne : 3 } } } , { $lookup : { from : 'exportd.jobs' , localField : 'job_id' , foreignField : 'public_id' , as : 'job' } } , { $match : { job : { $ne : { $size : 0 } } } } , { $project : { job : 0 } } ] ; if ( params . filter !== undefined ) { query . push ( params . filter ) ; } params . filter = query ; return this . getLogs ( params ) ; } public getLogsWithNotExistingJobs ( params = { filter : undefined , limit : 10 , sort : 'public_id' , order : 1 , page : 1 } ) { const query = [ { $match : { log_type : 'ExportdJobLog' } } , { $match : { action : { $ne : 3 } } } , { $lookup : { from : 'exportd.jobs' , localField : 'job_id' , foreignField : 'public_id' , as : 'job' } } , { $match : { job : { $size : 0 } } } , { $project : { job : 0 } } ] ; if ( params . filter !== undefined ) { query . push ( params . filter ) ; } params . filter = query ; return this . getLogs ( params ) ; } public getDeleteLogs ( ) { const options = this . options ; options . params = new HttpParams ( ) ; return this . api . callGet < T > ( `${ this . servicePrefix }/job/deleted/` , options ) . pipe ( map ( ( apiResponse ) => { if ( apiResponse . status === 204 ) { return [ ] ; } return apiResponse . body ; } ) ) ; } public deleteLog ( publicID ) { const options = this . options ; options . params = new HttpParams ( ) ; return this . api . callDelete < boolean > ( `${ this . servicePrefix }/${ publicID }/` , options ) . pipe ( map ( ( apiResponse ) => { return apiResponse . body ; } ) ) ; } }