import { subSeconds } from 'date-fns' import { FlowRunsFilter, TaskRunsFilter } from '@/models' import { MapFunction } from '@/services/Mapper' import { DeploymentStatsFilter } from '@/types/deployment' export const mapDeploymentStatsFilterToFlowRunsFilter: MapFunction = function(source) { const now = new Date() const filter: FlowRunsFilter = { deployments: { id: [source.deploymentId], }, flowRuns: { expectedStartTimeAfter: subSeconds(now, source.timeSpanInSeconds), expectedStartTimeBefore: now, }, } return filter } export const mapDeploymentStatsFilterToTaskRunsFilter: MapFunction = function(source) { const now = new Date() return { flows: { id: [source.deploymentId], }, taskRuns: { startTimeAfter: subSeconds(now, source.timeSpanInSeconds), startTimeBefore: now, }, } }