From 703e6ea01d4bb2fb38445d4f6182778ef51639c2 Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Sun, 1 Sep 2024 14:46:07 -0700 Subject: [PATCH] Fix empty projects --- apps/backend/src/app/api/v1/users/crud.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/backend/src/app/api/v1/users/crud.tsx b/apps/backend/src/app/api/v1/users/crud.tsx index c79bd8e5a..904246977 100644 --- a/apps/backend/src/app/api/v1/users/crud.tsx +++ b/apps/backend/src/app/api/v1/users/crud.tsx @@ -122,6 +122,11 @@ export const getUserLastActiveAtMillis = async (userId: string, fallbackTo: numb // same as userIds.map(userId => getUserLastActiveAtMillis(userId, fallbackTo)), but uses a single query export const getUsersLastActiveAtMillis = async (userIds: string[], fallbackTo: (number | Date)[]): Promise => { + if (userIds.length === 0) { + // Prisma.join throws an error if the array is empty, so we need to handle that case + return []; + } + const events = await prismaClient.$queryRaw>` SELECT data->>'userId' as "userId", MAX("createdAt") as "lastActiveAt" FROM "Event"