Skip to content

Commit

Permalink
fix: inArray requires atleast one value error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhravya committed Apr 15, 2024
1 parent bb15bde commit a784443
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions apps/web/src/app/api/store/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

await Promise.all([
spaceData.forEach(async (space) => {
await db
.insert(contentToSpace)
.values({ contentId: id, spaceId: space.id });
}),
]);
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 });
}),
]);
}

const res = (await Promise.race([
fetch("https://cf-ai-backend.dhravya.workers.dev/add", {
Expand Down

0 comments on commit a784443

Please sign in to comment.