Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {Injectable} from '@angular/core'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 2 | import {Observable} from 'rxjs'; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 3 | import {ServiceInfoModel} from './serviceInfo.model'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 4 | import {HttpClient, HttpHeaders} from '@angular/common/http'; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 5 | import {Constants} from '../../utils/constants'; |
| 6 | import {forkJoin} from "rxjs/observable/forkJoin"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 7 | import * as _ from 'lodash'; |
| 8 | import {AuditStatus} from "./AuditStatus.model"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 9 | |
| 10 | @Injectable() |
| 11 | export class ServiceInfoService { |
| 12 | constructor(private _http: HttpClient) { |
| 13 | } |
| 14 | |
Eylon Malin | d0a3e90 | 2019-12-02 10:55:37 +0200 | [diff] [blame] | 15 | getServicesJobInfo(showSpinner: boolean = true, serviceModelId: string = null): Observable<ServiceInfoModel[]> { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 16 | let pathQuery = Constants.Path.SERVICES_JOB_INFO_PATH; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 17 | let headers = new HttpHeaders({'x-show-spinner': showSpinner.toString()}); |
Eylon Malin | d0a3e90 | 2019-12-02 10:55:37 +0200 | [diff] [blame] | 18 | let params = serviceModelId ? {serviceModelId} : {}; |
| 19 | return this._http.get<ServiceInfoModel[]>(pathQuery, { headers: headers, params }); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | deleteJob(jobId: string): Observable<any> { |
| 23 | let pathQuery = Constants.Path.SERVICES_JOB_INFO_PATH + '/job/' + jobId; |
| 24 | return this._http.delete<any>(pathQuery).map(res => res); |
| 25 | } |
| 26 | |
| 27 | hideJob(jobId: string): Observable<any> { |
| 28 | let pathQuery = Constants.Path.SERVICES_JOB_INFO_PATH + '/hide/' + jobId; |
| 29 | return this._http.post<any>(pathQuery, null).map(res => res); |
| 30 | } |
| 31 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 32 | getJobAuditStatus(jobData: ServiceInfoModel) : Observable<Object[]>{ |
| 33 | let pathQueryBySource: string = Constants.Path.SERVICES_JOB_INFO_PATH + Constants.Path.SERVICES_JOB_AUDIT_PATH + '/' + jobData.jobId + '?source='; |
| 34 | let pathQueryVID: string = pathQueryBySource + 'VID'; |
| 35 | let pathQueryMSO: string; |
| 36 | |
| 37 | // just call it |
| 38 | if(jobData.aLaCarte) { |
| 39 | let requestParams: string[] = []; |
| 40 | pathQueryMSO = Constants.Path.SERVICES_JOB_INFO_PATH + Constants.Path.SERVICES_JOB_AUDIT_PATH + '/' + jobData.jobId + '/mso'; |
| 41 | if (!_.isEmpty(jobData.requestId)) { |
| 42 | requestParams[requestParams.length] = 'requestId=' + jobData.requestId; |
| 43 | } |
| 44 | if (!_.isEmpty(jobData.serviceInstanceId)) { |
| 45 | requestParams[requestParams.length] = 'serviceInstanceId=' + jobData.serviceInstanceId; |
| 46 | } |
| 47 | if (requestParams.length > 0) { |
| 48 | pathQueryMSO += '?' + requestParams.join('&'); |
| 49 | } |
| 50 | } |
| 51 | else { |
| 52 | pathQueryMSO = pathQueryBySource + 'MSO'; |
| 53 | } |
| 54 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 55 | |
| 56 | let vidObs = this._http.get(pathQueryVID); |
| 57 | let msoObs = this._http.get(pathQueryMSO); |
| 58 | return forkJoin([vidObs, msoObs]); |
| 59 | } |
| 60 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 61 | getInstanceAuditStatus(instanceId: string, type :string) : Observable<AuditStatus[]>{ |
| 62 | let pathQuery: string = Constants.Path.SERVICES_JOB_INFO_PATH + Constants.Path.SERVICES_JOB_AUDIT_PATH + '/' + type + '/' + instanceId + '/mso'; |
| 63 | return this._http.get<any>(pathQuery).map(res => res); |
| 64 | } |
| 65 | |
| 66 | getAuditStatusForRetry(trackById: string) : Observable<AuditStatus>{ |
| 67 | let pathQuery: string = Constants.Path.AUDIT_STATUS_FOR_RETRY_PATH + '/' + trackById ; |
| 68 | return this._http.get<any>(pathQuery).map(res => res); |
| 69 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 70 | } |