save, create and view reports in dashboard

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-19 11:56:52 +02:00
parent 2cb6bbfdd3
commit 4576453aef
28 changed files with 686 additions and 403 deletions

View File

@@ -21,6 +21,15 @@ const getBaseUrl = () => {
export const api = createTRPCNext<AppRouter>({
config() {
return {
queryClientConfig: {
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
refetchOnReconnect: false,
refetchOnMount: false,
}
}
},
/**
* Transformer used for data de-serialization from the server.
*

View File

@@ -2,4 +2,10 @@ export function getDaysOldDate(days: number) {
const date = new Date();
date.setDate(date.getDate() - days);
return date;
}
export function dateDifferanceInDays(date1: Date, date2: Date) {
const diffTime = Math.abs(date2.getTime() - date1.getTime());
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}
}

View File

@@ -1,3 +1,4 @@
import { ChartType } from "@prisma/client";
import { z } from "zod";
export const zChartEvent = z.object({
@@ -19,6 +20,16 @@ export const zChartBreakdown = z.object({
export const zChartEvents = z.array(zChartEvent);
export const zChartBreakdowns = z.array(zChartBreakdown);
export const zChartType = z.enum(["bar", "linear"]);
export const zChartType = z.enum(['linear', 'bar', 'pie', 'metric', 'area']);
export const zTimeInterval = z.enum(["day", "hour", "month"]);
export const zChartInput = z.object({
name: z.string(),
startDate: z.date(),
endDate: z.date(),
chartType: zChartType,
interval: zTimeInterval,
events: zChartEvents,
breakdowns: zChartBreakdowns,
})