Skip to content

Scheduling infrastructure for absolutely everyone.

fix: apply user timeZone for Event Trends on /insights (#21787)

Eunjae Leeafc28503a506
diff --git a/packages/features/insights/server/events.ts b/packages/features/insights/server/events.ts
index cc533fa144f..b600e52f9c8 100644
--- a/packages/features/insights/server/events.ts
+++ b/packages/features/insights/server/events.ts
@@ -80,7 +80,8 @@ class EventsInsights {
whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput,
startDate: Dayjs,
endDate: Dayjs,
- dateRanges: DateRange[]
+ dateRanges: DateRange[],
+ timeZone: string
): Promise<AggregateResult> => {
const formattedStartDate = dayjs(startDate).format("YYYY-MM-DD HH:mm:ss");
const formattedEndDate = dayjs(endDate).format("YYYY-MM-DD HH:mm:ss");
@@ -96,14 +97,14 @@ class EventsInsights {
}[]
>`
SELECT
- DATE("createdAt") as "date",
+ "date",
CAST(COUNT(*) AS INTEGER) AS "bookingsCount",
CAST(COUNT(CASE WHEN "isNoShowGuest" = true THEN 1 END) AS INTEGER) AS "noShowGuests",
"timeStatus",
"noShowHost"
FROM (
SELECT
- "createdAt",
+ DATE("createdAt" AT TIME ZONE ${timeZone}) as "date",
"a"."noShow" AS "isNoShowGuest",
"timeStatus",
"noShowHost"
@@ -116,7 +117,7 @@ class EventsInsights {
AND ${Prisma.raw(whereClause)}
) AS bookings
GROUP BY
- DATE("createdAt"),
+ "date",
"timeStatus",
"noShowHost"
ORDER BY
diff --git a/packages/features/insights/server/trpc-router.ts b/packages/features/insights/server/trpc-router.ts
index edce11db31c..c141550125f 100644
--- a/packages/features/insights/server/trpc-router.ts
+++ b/packages/features/insights/server/trpc-router.ts
@@ -489,7 +489,8 @@ export const insightsRouter = router({
whereConditional,
dayjs(startDate),
dayjs(endDate),
- dateRanges
+ dateRanges,
+ ctx.user.timeZone
);
const result = dateRanges.map(({ formattedDate }) => {