added limit

This commit is contained in:
Dhravya 2024-04-14 13:59:32 -07:00
parent 0a2956436e
commit d099d4bda9

View file

@ -82,9 +82,19 @@ export async function POST(req: NextRequest) {
count: sql<number>`count(*)`.mapWith(Number),
})
.from(storedContent)
.where(eq(storedContent.user, session.user.id));
.where(
and(
eq(storedContent.user, session.user.id),
eq(storedContent.type, "page"),
),
);
console.log("count", count[0].count);
if (count[0].count > 100) {
return NextResponse.json(
{ message: "Error", error: "Limit exceeded" },
{ status: 499 },
);
}
const { id } = (
await db