Skip to content

Commit 626585f

Browse files
fix: Handle empty array in Prisma OR conditions for Prisma 6.16 (calcom#24638)
After upgrading to Prisma 6.16.0, empty arrays in 'in' clauses within OR conditions are now optimized to return no results. This caused integration tests to fail when querying memberships with empty memberUserIds arrays. Changes: - Dynamically build OR conditions to exclude empty 'in' arrays - Simplify getAllAdminMemberships to use 'in' instead of OR for roles - Fixes retrieveScopedAccessibleUsers and getAccessibleUsers queries Fixes integration test failures: - apps/api/v1/test/lib/utils/retrieveScopedAccessibleUsers.integration-test.ts - apps/api/v1/test/lib/bookings/[id]/_patch.integration-test.ts Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 4d3727d commit 626585f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

apps/api/v1/lib/utils/retrieveScopedAccessibleUsers.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const getAllAdminMemberships = async (userId: number) => {
2727
where: {
2828
userId: userId,
2929
accepted: true,
30-
OR: [{ role: MembershipRole.OWNER }, { role: MembershipRole.ADMIN }],
30+
role: { in: [MembershipRole.OWNER, MembershipRole.ADMIN] },
3131
},
3232
select: {
3333
team: {
@@ -56,16 +56,19 @@ export const getAccessibleUsers = async ({
5656
memberUserIds,
5757
adminUserId,
5858
}: AccessibleUsersType): Promise<number[]> => {
59+
const orConditions = [];
60+
if (memberUserIds.length > 0) {
61+
orConditions.push({ userId: { in: memberUserIds } });
62+
}
63+
orConditions.push({ userId: adminUserId, role: { in: [MembershipRole.OWNER, MembershipRole.ADMIN] } });
64+
5965
const memberships = await prisma.membership.findMany({
6066
where: {
6167
team: {
6268
isOrganization: true,
6369
},
6470
accepted: true,
65-
OR: [
66-
{ userId: { in: memberUserIds } },
67-
{ userId: adminUserId, role: { in: [MembershipRole.OWNER, MembershipRole.ADMIN] } },
68-
],
71+
OR: orConditions,
6972
},
7073
select: {
7174
userId: true,

0 commit comments

Comments
 (0)