import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Config } from './types/config'; import { FormValues } from './types/form-values'; import { catchError, retry } from 'rxjs/operators'; import { Observable } from 'rxjs'; import { ExtraOptions } from './types/extra-options'; import { ActionPlanRepresentation } from './types/action-plan'; import { IcsToastService } from '@varmasagi/ics-toast'; import { DatePipe } from '@angular/common'; import { isNullOrUndefined } from 'util'; @Injectable() export class IcsActionPlanService { pr; constructor( private httpClient: HttpClient, private config: Config, private extraOptions: ExtraOptions, private toast: IcsToastService ) { } public getFormValues(appId: any): Observable { return this.httpClient .get(`${this.config.url}action-plan/form-values/${appId}`); } public createAction(representation: ActionPlanRepresentation): Observable { const datePipe = new DatePipe('en-US'); if (typeof representation.category === 'string') { representation.category = { name: representation.category, value: null }; } if (typeof representation.area === 'string') { representation.area = { name: representation.area, value: null }; } if (typeof representation.metric === 'string') { representation.metric = { name: representation.metric, value: null }; } representation.proposedDate = datePipe.transform(representation.proposedDate, 'yyyy-MM-dd'); return this.httpClient .post(`${this.config.url}action-plan`, representation, { observe: 'response' }); } }