From afc28503a5063a769ca20a4082201144523c6c1f Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Fri, 13 Jun 2025 06:47:47 +0200 Subject: [PATCH] fix: apply user timeZone for Event Trends on /insights (#21787) --- packages/features/insights/server/events.ts | 9 +++++---- packages/features/insights/server/trpc-router.ts | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/features/insights/server/events.ts b/packages/features/insights/server/events.ts index cc533fa144..b600e52f9c 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 => { 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 edce11db31..c141550125 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 }) => {