From a78444313f8e223167c136b9d0c44d248f24c110 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Mon, 15 Apr 2024 14:41:55 -0700 Subject: [PATCH] fix: inArray requires atleast one value error --- apps/web/src/app/api/store/route.ts | 33 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/web/src/app/api/store/route.ts b/apps/web/src/app/api/store/route.ts index f9c1ea40..457eae2e 100644 --- a/apps/web/src/app/api/store/route.ts +++ b/apps/web/src/app/api/store/route.ts @@ -119,21 +119,26 @@ export async function POST(req: NextRequest) { ); } - const spaceData = await db - .select() - .from(space) - .where( - and(inArray(space.name, storeToSpaces), eq(space.user, session.user.id)), - ) - .all(); + if (storeToSpaces.length > 0) { + const spaceData = await db + .select() + .from(space) + .where( + and( + inArray(space.name, storeToSpaces ?? []), + eq(space.user, session.user.id), + ), + ) + .all(); - await Promise.all([ - spaceData.forEach(async (space) => { - await db - .insert(contentToSpace) - .values({ contentId: id, spaceId: space.id }); - }), - ]); + await Promise.all([ + spaceData.forEach(async (space) => { + await db + .insert(contentToSpace) + .values({ contentId: id, spaceId: space.id }); + }), + ]); + } const res = (await Promise.race([ fetch("https://cf-ai-backend.dhravya.workers.dev/add", {