diff --git a/server/api/user/[id]/block.post.ts b/server/api/user/[id]/block.post.ts new file mode 100644 index 0000000..7e59889 --- /dev/null +++ b/server/api/user/[id]/block.post.ts @@ -0,0 +1,19 @@ +import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; +import { User } from "~/models/user"; + +export default eventHandler(async (ev) => { + isLoggedIn(ev); + let idee = parseInt(getRouterParam(ev, "id")!); + if (isNaN(idee)) + throw createError({ + statusCode: 400, + }); + await User.findOneAndUpdate( + { _id: ev.context.currentUser!._id }, + { + $addToSet: { + blocked: idee, + }, + }, + ); +}); diff --git a/server/api/user/[id]/unblock.post.ts b/server/api/user/[id]/unblock.post.ts new file mode 100644 index 0000000..0ca732d --- /dev/null +++ b/server/api/user/[id]/unblock.post.ts @@ -0,0 +1,19 @@ +import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; +import { User } from "~/models/user"; + +export default eventHandler(async (ev) => { + isLoggedIn(ev); + let idee = parseInt(getRouterParam(ev, "id")!); + if (isNaN(idee)) + throw createError({ + statusCode: 400, + }); + await User.findOneAndUpdate( + { _id: ev.context.currentUser!._id }, + { + $pull: { + blocked: idee, + }, + }, + ); +});