2023-12-20 17:23:31 -05:00
|
|
|
import { HidePayload } from "@client/types/form/favSub";
|
|
|
|
import isLoggedIn from "@server/middlewareButNotReally/isLoggedIn";
|
|
|
|
import { User } from "@models/user";
|
2023-10-11 16:44:31 -04:00
|
|
|
|
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
isLoggedIn(ev);
|
|
|
|
const body = await readBody<HidePayload>(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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|