feature(dashboard): add conversion rate graph
This commit is contained in:
@@ -5,6 +5,7 @@ import { z } from 'zod';
|
||||
import {
|
||||
TABLE_NAMES,
|
||||
chQuery,
|
||||
conversionService,
|
||||
createSqlBuilder,
|
||||
db,
|
||||
funnelService,
|
||||
@@ -32,7 +33,6 @@ import {
|
||||
getChart,
|
||||
getChartPrevStartEndDate,
|
||||
getChartStartEndDate,
|
||||
getFunnelData,
|
||||
} from './chart.helpers';
|
||||
|
||||
function utc(date: string | Date) {
|
||||
@@ -197,6 +197,29 @@ export const chartRouter = createTRPCRouter({
|
||||
};
|
||||
}),
|
||||
|
||||
conversion: protectedProcedure.input(zChartInput).query(async ({ input }) => {
|
||||
const currentPeriod = getChartStartEndDate(input);
|
||||
const previousPeriod = getChartPrevStartEndDate(currentPeriod);
|
||||
|
||||
const [current, previous] = await Promise.all([
|
||||
conversionService.getConversion({ ...input, ...currentPeriod }),
|
||||
input.previous
|
||||
? conversionService.getConversion({ ...input, ...previousPeriod })
|
||||
: Promise.resolve(null),
|
||||
]);
|
||||
|
||||
return {
|
||||
current: current.map((serie, sIndex) => ({
|
||||
...serie,
|
||||
data: serie.data.map((d, dIndex) => ({
|
||||
...d,
|
||||
previousRate: previous?.[sIndex]?.data?.[dIndex]?.rate,
|
||||
})),
|
||||
})),
|
||||
previous,
|
||||
};
|
||||
}),
|
||||
|
||||
chart: publicProcedure.input(zChartInput).query(async ({ input, ctx }) => {
|
||||
if (ctx.session.userId) {
|
||||
const access = await getProjectAccessCached({
|
||||
|
||||
Reference in New Issue
Block a user