]>
Commit | Line | Data |
---|---|---|
5cd80545 C |
1 | import { HttpClient, HttpParams } from '@angular/common/http' |
2 | import { Injectable } from '@angular/core' | |
3 | import { SortMeta } from 'primeng/primeng' | |
4 | import 'rxjs/add/operator/catch' | |
5 | import 'rxjs/add/operator/map' | |
6 | import { Observable } from 'rxjs/Observable' | |
7 | import { ResultList } from '../../../../../../shared' | |
8 | import { Job } from '../../../../../../shared/models/job.model' | |
63c4db6d | 9 | import { environment } from '../../../../environments/environment' |
5cd80545 C |
10 | import { RestExtractor, RestPagination, RestService } from '../../../shared' |
11 | ||
12 | @Injectable() | |
13 | export class JobService { | |
63c4db6d | 14 | private static BASE_JOB_URL = environment.apiUrl + '/api/v1/jobs' |
5cd80545 C |
15 | |
16 | constructor ( | |
17 | private authHttp: HttpClient, | |
18 | private restService: RestService, | |
19 | private restExtractor: RestExtractor | |
20 | ) {} | |
21 | ||
22 | getJobs (pagination: RestPagination, sort: SortMeta): Observable<ResultList<Job>> { | |
23 | let params = new HttpParams() | |
24 | params = this.restService.addRestGetParams(params, pagination, sort) | |
25 | ||
26 | return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL, { params }) | |
27 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) | |
cd83ea1b | 28 | .map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)) |
5cd80545 C |
29 | .catch(err => this.restExtractor.handleError(err)) |
30 | } | |
cd83ea1b C |
31 | |
32 | private prettyPrintData (obj: Job) { | |
33 | const handlerInputData = JSON.stringify(obj.handlerInputData, null, 2) | |
34 | ||
35 | return Object.assign(obj, { handlerInputData }) | |
36 | } | |
5cd80545 | 37 | } |