diff options
| author | Dhravya <[email protected]> | 2024-05-25 23:38:48 -0500 |
|---|---|---|
| committer | Dhravya <[email protected]> | 2024-05-25 23:38:48 -0500 |
| commit | c12ecfc4316a6f37d2d07c57e4dfefa231783c0d (patch) | |
| tree | c04612a8db2b06060e1e1087ef298fa124aa71e4 /apps/web/app/api/getCount | |
| parent | fix global file stuff (diff) | |
| download | supermemory-c12ecfc4316a6f37d2d07c57e4dfefa231783c0d.tar.xz supermemory-c12ecfc4316a6f37d2d07c57e4dfefa231783c0d.zip | |
brought all the APIs back
Diffstat (limited to 'apps/web/app/api/getCount')
| -rw-r--r-- | apps/web/app/api/getCount/route.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/apps/web/app/api/getCount/route.ts b/apps/web/app/api/getCount/route.ts new file mode 100644 index 00000000..f760c145 --- /dev/null +++ b/apps/web/app/api/getCount/route.ts @@ -0,0 +1,47 @@ +import { db } from "@/app/helpers/server/db"; +import { and, eq, ne, sql } from "drizzle-orm"; +import { sessions, storedContent, users } from "@/app/helpers/server/db/schema"; +import { type NextRequest, NextResponse } from "next/server"; +import { ensureAuth } from "../ensureAuth"; + +export const runtime = "edge"; + +export async function GET(req: NextRequest) { + const session = await ensureAuth(req); + + if (!session) { + return new Response("Unauthorized", { status: 401 }); + } + + const tweetsCount = await db + .select({ + count: sql<number>`count(*)`.mapWith(Number), + }) + .from(storedContent) + .where( + and( + eq(storedContent.user, session.user.id), + eq(storedContent.type, "twitter-bookmark"), + ), + ); + + const pageCount = await db + .select({ + count: sql<number>`count(*)`.mapWith(Number), + }) + .from(storedContent) + .where( + and( + eq(storedContent.user, session.user.id), + ne(storedContent.type, "twitter-bookmark"), + ), + ); + + return NextResponse.json({ + tweetsCount: tweetsCount[0]!.count, + tweetsLimit: 1000, + pageCount: pageCount[0]!.count, + pageLimit: 100, + user: session.user.email, + }); +} |