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

This commit is contained in:
Eunjae Lee authored and GitHub committed 2025-06-13 08:47:47 +04:00
1 parent e6497c87ca
commit afc28503a5
2 files changed
+7 -5

No files matched your search

+5 -4
View File
@@ -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
@@ -489,7 +489,8 @@ export const insightsRouter = router({
whereConditional,
dayjs(startDate),
dayjs(endDate),
dateRanges
dateRanges,
ctx.user.timeZone
);
const result = dateRanges.map(({ formattedDate }) => {