From 99dc5837f50e29ed3ac14e7fc619b35c03a258dd Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Thu, 1 May 2025 17:51:49 +0200 Subject: [PATCH] revert: "fix: eventType filter on /insights (#20823)" (#21059) This reverts commit 45904c07bc82094fbe917c10948ac2de54c6d70d. --- .../features/insights/server/trpc-router.ts | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/packages/features/insights/server/trpc-router.ts b/packages/features/insights/server/trpc-router.ts index 8bb69a4664..58a687fcb2 100644 --- a/packages/features/insights/server/trpc-router.ts +++ b/packages/features/insights/server/trpc-router.ts @@ -53,9 +53,8 @@ const buildBaseWhereCondition = async ({ isEmptyResponse?: boolean; }> => { let whereCondition: Prisma.BookingTimeStatusWhereInput = {}; - const ANDConditions: Prisma.BookingTimeStatusWhereInput[] = []; // EventType Filter - if (eventTypeId) ANDConditions.push({ OR: [{ eventTypeId }, { eventParentId: eventTypeId }] }); + if (eventTypeId) whereCondition.OR = [{ eventTypeId }, { eventParentId: eventTypeId }]; // User/Member filter if (memberUserId) whereCondition.userId = memberUserId; if (userId) { @@ -77,9 +76,13 @@ const buildBaseWhereCondition = async ({ return { whereCondition: { ...whereCondition, - teamId: ctx.userOrganizationId, - isTeamBooking: true, - ...(ANDConditions.length > 0 ? { AND: [...ANDConditions] } : {}), + OR: [ + ...(whereCondition.OR ?? []), + { + teamId: ctx.userOrganizationId, + isTeamBooking: true, + }, + ], }, isEmptyResponse: true, }; @@ -102,23 +105,18 @@ const buildBaseWhereCondition = async ({ const userIdsFromOrg = usersFromOrg.map((u) => u.userId); whereCondition = { ...whereCondition, - AND: [ - ...ANDConditions, + OR: [ { - OR: [ - { - teamId: { - in: [ctx.userOrganizationId, ...teamsFromOrg.map((t) => t.id)], - }, - isTeamBooking: true, - }, - { - userId: { - in: userIdsFromOrg, - }, - isTeamBooking: false, - }, - ], + teamId: { + in: [ctx.userOrganizationId, ...teamsFromOrg.map((t) => t.id)], + }, + isTeamBooking: true, + }, + { + userId: { + in: userIdsFromOrg, + }, + isTeamBooking: false, }, ], }; @@ -137,21 +135,16 @@ const buildBaseWhereCondition = async ({ const userIdsFromTeam = usersFromTeam.map((u) => u.userId); whereCondition = { ...whereCondition, - AND: [ - ...ANDConditions, + OR: [ { - OR: [ - { - teamId, - isTeamBooking: true, - }, - { - userId: { - in: userIdsFromTeam, - }, - isTeamBooking: false, - }, - ], + teamId, + isTeamBooking: true, + }, + { + userId: { + in: userIdsFromTeam, + }, + isTeamBooking: false, }, ], };