From 8bf78a049458e9169f0809f90da86c2e0e2926af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Tue, 10 Oct 2023 21:54:37 -0400 Subject: [PATCH] feat(api): add endpoint to get all non-hidden stories a user has written --- server/api/user/[id]/stories.get.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 server/api/user/[id]/stories.get.ts diff --git a/server/api/user/[id]/stories.get.ts b/server/api/user/[id]/stories.get.ts new file mode 100644 index 0000000..24dd936 --- /dev/null +++ b/server/api/user/[id]/stories.get.ts @@ -0,0 +1,11 @@ +import listQuerier from "~/lib/server/dbHelpers/listQuerier"; + +export default cachedEventHandler(async (ev) => { + const id = parseInt(getRouterParam(ev, "id")!); + let s = await listQuerier({ author: { $in: [id] } }, ev.context); + const t = s.map((a) => a.toObject()); + return { + stories: t, + total: t.length, + }; +});