import { round } from 'lodash'; import { map } from 'rxjs/operators'; import { MaerskApiClient } from '../../../common/clients/maerskApi.client'; import { ForecastCalculations, ForecastCalculationsDto } from '../store/forecast.types'; export class ForecastService { private apiClient: MaerskApiClient; constructor(apiClient) { this.apiClient = apiClient; } createAggregation = (data: ForecastCalculationsDto): ForecastCalculations => { data.sort((a, b) => { return a.date > b.date ? 1 : -1; }); return data.map((item, index) => ({ id: index, date: item.date, createdAt: item.createdAt, currentCalculatedRate: item.currentCalculatedRate, fixedPercentage: round(item.fixedRatio * 100), fixedRate: item.fixedRate, unfixedPercentage: round(100 - item.fixedRatio * 100), unfixedRate: item.unfixedRate, payoutRatio: item.payoutRatio, type: item.type, previousCalculatedRate: item.previousCalculatedRate, trend: item.trend, })); } getForecast = (poolId) => { return this.apiClient.getForecast(poolId).pipe( map(this.createAggregation) ); } }