import api from 'api' ; import { Dispatch } from 'redux' ; import { toUTCEpoch } from 'utils/timeUtils' ; import { ActionTypes } from './types' ; export interface usageDataItem { timestamp : number ; count : number ; } export interface getUsageDataAction { type : ActionTypes . getUsageData ; payload : usageDataItem [ ] ; } export const getUsageData = ( minTime , maxTime , step , service ) => { return async ( dispatch ) : Promise < void > => { const request_string = `/usage?start=${ toUTCEpoch ( minTime ) }&end=${ toUTCEpoch ( maxTime ) }&step=${ step }&service=${ service ? service : '' }` ; const response = await api . get < usageDataItem [ ] > ( request_string ) ; dispatch < getUsageDataAction > ( { type : ActionTypes . getUsageData , payload : response . data , } ) ; } ; } ;