From ec88f16f1f5e98bfdeb58fee0d641af8912cd026 Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Wed, 23 Apr 2025 19:22:20 +0300 Subject: [PATCH] fix: getBookings max 1 month in the past when no date filters specified (#20911) * fix: getBookings max 1 month in the past * bump platform libraries --- apps/api/v2/package.json | 2 +- .../routers/viewer/bookings/get.handler.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index 12c7e9b870..e61061c6b0 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -38,7 +38,7 @@ "@axiomhq/winston": "^1.2.0", "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.174", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.176", "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", diff --git a/packages/trpc/server/routers/viewer/bookings/get.handler.ts b/packages/trpc/server/routers/viewer/bookings/get.handler.ts index 6ca4177baf..603808cc56 100644 --- a/packages/trpc/server/routers/viewer/bookings/get.handler.ts +++ b/packages/trpc/server/routers/viewer/bookings/get.handler.ts @@ -334,6 +334,26 @@ export async function getBookings({ andConditions.push({ createdAt: { lte: dayjs.utc(filters.beforeCreatedDate).toDate() } }); } + // All the possible date filter keys + const dateFilterKeys = [ + "afterStartDate", + "beforeEndDate", + "afterUpdatedDate", + "beforeUpdatedDate", + "afterCreatedDate", + "beforeCreatedDate", + ] as const; + + const hasAnyDateFilter = dateFilterKeys.some((key) => filters?.[key]); + + if (!hasAnyDateFilter) { + // is ORG/TEAM admin/owner + if (userIdsWhereUserIsAdminOrOwner?.length || userEmailsWhereUserIsAdminOrOwner?.length) { + const oneMonthAgo = dayjs.utc().subtract(1, "month").startOf("day").toDate(); + andConditions.push({ startTime: { gte: oneMonthAgo } }); + } + } + const whereClause = { OR: orConditions, AND: andConditions,