2023-10-11 16:45:39 -04:00
|
|
|
import san from "sanitize-html";
|
|
|
|
import axios from "axios";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { Profile } from "@client/types/form/myStuff";
|
|
|
|
import { apiRoot, h2m } from "@server/constants";
|
|
|
|
import forumId from "@server/forumId";
|
2023-12-29 16:32:32 -05:00
|
|
|
import { isLoggedIn } from "@server/middlewareButNotReally";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { User } from "@models/user";
|
2023-10-11 16:45:39 -04:00
|
|
|
|
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
isLoggedIn(ev);
|
|
|
|
const body = await readBody<Profile>(ev);
|
|
|
|
const update: any = {
|
|
|
|
"profile.occupation": body.occupation,
|
|
|
|
"profile.website": body.website,
|
|
|
|
"profile.blog": body.blog,
|
|
|
|
"profile.bio": san(body.bio),
|
|
|
|
"profile.showEmail": !!body.showEmail,
|
|
|
|
};
|
|
|
|
let d = {
|
2023-12-29 16:32:32 -05:00
|
|
|
signature: h2m.turndown(body.signature || ""),
|
2023-10-11 16:45:39 -04:00
|
|
|
_uid: 1,
|
|
|
|
};
|
|
|
|
let lookup = await forumId(ev.context.currentUser!._id!);
|
|
|
|
await axios.put(`${apiRoot}/v3/users/${lookup}`, {
|
|
|
|
body: d,
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${useRuntimeConfig().nodebb.masterToken}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await User.findByIdAndUpdate(ev.context.currentUser?._id, {
|
|
|
|
$set: update,
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
message: "Profile updated successfully",
|
|
|
|
};
|
|
|
|
});
|