From 25af14ceea96212b62d7d038aeca348b1ca899a5 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: Wed, 11 Oct 2023 16:44:31 -0400 Subject: [PATCH] feat(api): create endpoint for managing hidden bands/authors --- server/api/user/me/hide.put.ts | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 server/api/user/me/hide.put.ts diff --git a/server/api/user/me/hide.put.ts b/server/api/user/me/hide.put.ts new file mode 100644 index 0000000..58a4037 --- /dev/null +++ b/server/api/user/me/hide.put.ts @@ -0,0 +1,39 @@ +import { HidePayload } from "~/lib/client/types/form/favSub"; +import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; +import { User } from "~/models/user"; + +export default eventHandler(async (ev) => { + isLoggedIn(ev); + const body = await readBody(ev); + await User.findByIdAndUpdate(ev.context.currentUser!._id, { + $pull: { + hiddenAuthors: { + $in: body.pull?.authors || [], + }, + hiddenBands: { + $in: body.pull?.bands || [], + }, + }, + }); + const nu: any = await User.findByIdAndUpdate( + ev.context.currentUser!._id, + { + $addToSet: { + hiddenAuthors: { + $each: body.pull?.authors || [], + }, + hiddenBands: { + $each: body.pull?.bands || [], + }, + }, + }, + { new: true }, + ); + return { + success: true, + data: { + hiddenBands: nu?.hiddenBands, + hiddenAuthors: nu?.hiddenAuthors, + }, + }; +});