Fix user settings not saving properly and guild folders

This commit is contained in:
Madeline committed 2022-10-28 19:23:02 +11:00
1 parent 78962acc9d
commit 00e3606f7c
6 files changed
+11 -12

No files matched your search

+5 -4
View File
@@ -1,5 +1,5 @@
import { Router, Response, Request } from "express";
import { User, UserSettings } from "@fosscord/util";
import { OrmUtils, User, UserSettingsSchema } from "@fosscord/util";
import { route } from "@fosscord/api";
const router = Router();
@@ -16,14 +16,15 @@ router.patch(
"/",
route({ body: "UserSettingsSchema" }),
async (req: Request, res: Response) => {
const body = req.body as UserSettings;
const body = req.body as UserSettingsSchema;
if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale
const user = await User.findOneOrFail({
where: { id: req.user_id, bot: false },
select: ["settings"]
});
user.settings = { ...user.settings, ...body };
await user.save();
user.settings = OrmUtils.mergeDeep(user.settings, body);
User.update({ id: user.id }, { settings: user.settings });
res.json(user.settings);
},