reduce chart payload

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-17 22:12:04 +02:00
parent f417c0f682
commit 626a6fd938
26 changed files with 407 additions and 367 deletions

View File

@@ -71,6 +71,8 @@ export const zChartInput = z.object({
projectId: z.string(),
startDate: z.string().nullish(),
endDate: z.string().nullish(),
limit: z.number().optional(),
offset: z.number().optional(),
});
export const zReportInput = zChartInput.extend({

View File

@@ -31,9 +31,54 @@ export type IChartType = z.infer<typeof zChartType>;
export type IChartMetric = z.infer<typeof zMetric>;
export type IChartLineType = z.infer<typeof zLineType>;
export type IChartRange = z.infer<typeof zRange>;
export interface IChartInputWithDates extends IChartInput {
startDate: string;
endDate: string;
}
export type IGetChartDataInput = {
event: IChartEvent;
projectId: string;
startDate: string;
endDate: string;
} & Omit<IChartInput, 'events' | 'name' | 'startDate' | 'endDate' | 'range'>;
export type PreviousValue =
| {
value: number;
diff: number | null;
state: 'positive' | 'negative' | 'neutral';
}
| undefined;
export type Metrics = {
sum: number;
average: number;
min: number;
max: number;
previous?: {
sum: PreviousValue;
average: PreviousValue;
min: PreviousValue;
max: PreviousValue;
};
};
export type IChartSerie = {
id: string;
name: string;
event: {
id: string;
name: string;
};
metrics: Metrics;
data: {
date: string;
count: number;
previous: PreviousValue;
}[];
};
export type FinalChart = {
series: IChartSerie[];
metrics: Metrics;
};