fix: improve types for chart/reports
This commit is contained in:
@@ -27,7 +27,7 @@ import {
|
||||
} from '@openpanel/db';
|
||||
import {
|
||||
type IChartEvent,
|
||||
zChartInput,
|
||||
zReportInput,
|
||||
zChartSeries,
|
||||
zCriteria,
|
||||
zRange,
|
||||
@@ -335,7 +335,7 @@ export const chartRouter = createTRPCRouter({
|
||||
|
||||
funnel: publicProcedure
|
||||
.input(
|
||||
zChartInput.and(
|
||||
zReportInput.and(
|
||||
z.object({
|
||||
shareId: z.string().optional(),
|
||||
reportId: z.string().optional(),
|
||||
@@ -417,7 +417,7 @@ export const chartRouter = createTRPCRouter({
|
||||
|
||||
conversion: publicProcedure
|
||||
.input(
|
||||
zChartInput.and(
|
||||
zReportInput.and(
|
||||
z.object({
|
||||
shareId: z.string().optional(),
|
||||
reportId: z.string().optional(),
|
||||
@@ -511,7 +511,7 @@ export const chartRouter = createTRPCRouter({
|
||||
};
|
||||
}),
|
||||
|
||||
sankey: protectedProcedure.input(zChartInput).query(async ({ input }) => {
|
||||
sankey: protectedProcedure.input(zReportInput).query(async ({ input }) => {
|
||||
const { timezone } = await getSettingsForProject(input.projectId);
|
||||
const currentPeriod = getChartStartEndDate(input, timezone);
|
||||
|
||||
@@ -546,7 +546,7 @@ export const chartRouter = createTRPCRouter({
|
||||
chart: publicProcedure
|
||||
// .use(cacher)
|
||||
.input(
|
||||
zChartInput.and(
|
||||
zReportInput.and(
|
||||
z.object({
|
||||
shareId: z.string().optional(),
|
||||
reportId: z.string().optional(),
|
||||
@@ -606,7 +606,7 @@ export const chartRouter = createTRPCRouter({
|
||||
|
||||
aggregate: publicProcedure
|
||||
.input(
|
||||
zChartInput.and(
|
||||
zReportInput.and(
|
||||
z.object({
|
||||
shareId: z.string().optional(),
|
||||
reportId: z.string().optional(),
|
||||
@@ -721,7 +721,8 @@ export const chartRouter = createTRPCRouter({
|
||||
}
|
||||
|
||||
projectId = report.projectId;
|
||||
criteria = report.criteria ?? criteria;
|
||||
const retentionOptions = report.options?.type === 'retention' ? report.options : undefined;
|
||||
criteria = retentionOptions?.criteria ?? criteria;
|
||||
dateRange = input.range ?? report.range;
|
||||
startDate = input.startDate ?? report.startDate;
|
||||
endDate = input.endDate ?? report.endDate;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { db, getReportById, getReportsByDashboardId } from '@openpanel/db';
|
||||
import { zReportInput } from '@openpanel/validation';
|
||||
import { zReport } from '@openpanel/validation';
|
||||
|
||||
import { getProjectAccess } from '../access';
|
||||
import { TRPCAccessError } from '../errors';
|
||||
@@ -21,7 +21,7 @@ export const reportRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
report: zReportInput.omit({ projectId: true }),
|
||||
report: zReport.omit({ projectId: true }),
|
||||
dashboardId: z.string(),
|
||||
}),
|
||||
)
|
||||
@@ -55,10 +55,7 @@ export const reportRouter = createTRPCRouter({
|
||||
formula: report.formula,
|
||||
previous: report.previous ?? false,
|
||||
unit: report.unit,
|
||||
criteria: report.criteria,
|
||||
metric: report.metric === 'count' ? 'sum' : report.metric,
|
||||
funnelGroup: report.funnelGroup,
|
||||
funnelWindow: report.funnelWindow,
|
||||
options: report.options,
|
||||
},
|
||||
});
|
||||
@@ -67,7 +64,7 @@ export const reportRouter = createTRPCRouter({
|
||||
.input(
|
||||
z.object({
|
||||
reportId: z.string(),
|
||||
report: zReportInput.omit({ projectId: true }),
|
||||
report: zReport.omit({ projectId: true }),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input: { report, reportId }, ctx }) => {
|
||||
@@ -101,10 +98,7 @@ export const reportRouter = createTRPCRouter({
|
||||
formula: report.formula,
|
||||
previous: report.previous ?? false,
|
||||
unit: report.unit,
|
||||
criteria: report.criteria,
|
||||
metric: report.metric === 'count' ? 'sum' : report.metric,
|
||||
funnelGroup: report.funnelGroup,
|
||||
funnelWindow: report.funnelWindow,
|
||||
options: report.options,
|
||||
},
|
||||
});
|
||||
@@ -173,10 +167,7 @@ export const reportRouter = createTRPCRouter({
|
||||
formula: report.formula,
|
||||
previous: report.previous,
|
||||
unit: report.unit,
|
||||
criteria: report.criteria,
|
||||
metric: report.metric,
|
||||
funnelGroup: report.funnelGroup,
|
||||
funnelWindow: report.funnelWindow,
|
||||
options: report.options,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user