From f0346ebdbd0cd3f15108c93a19a94a93f845a11f 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, 3 Oct 2023 01:18:12 -0400 Subject: [PATCH] feat(api): add an endpoint to retrieve the users who have favourited a specific story --- server/api/story/[id]/lovers.get.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 server/api/story/[id]/lovers.get.ts diff --git a/server/api/story/[id]/lovers.get.ts b/server/api/story/[id]/lovers.get.ts new file mode 100644 index 0000000..42759c0 --- /dev/null +++ b/server/api/story/[id]/lovers.get.ts @@ -0,0 +1,13 @@ +import { User } from "~/models/user"; + +export default eventHandler(async (ev) => { + const id = parseInt(getRouterParam(ev, "id") as string); + let dat = await User.find({ + "favs.stories": { + $in: [id], + }, + }) + .select("-auth -email -ipLog -password") + .exec(); + return dat.map((a) => a.toObject()); +});