feat(api): add endpoints for blocking/unblocking a specific user
This commit is contained in:
parent
8bf78a0494
commit
6afc547f8e
19
server/api/user/[id]/block.post.ts
Normal file
19
server/api/user/[id]/block.post.ts
Normal file
@ -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,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
19
server/api/user/[id]/unblock.post.ts
Normal file
19
server/api/user/[id]/unblock.post.ts
Normal file
@ -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,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue
Block a user