summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-28 19:23:02 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-28 19:23:02 +1100
commit00e3606f7c99eb3f9b4c6f9e0eb72234eb7d584a (patch)
tree05645586399601f7349cade5480897e08b78c2f7 /src
parentlol (diff)
downloadserver-00e3606f7c99eb3f9b4c6f9e0eb72234eb7d584a.tar.xz
Fix user settings not saving properly and guild folders
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/users/@me/settings.ts9
-rw-r--r--src/util/entities/User.ts6
-rw-r--r--src/util/schemas/UserGuildSettingsSchema.ts2
-rw-r--r--src/util/schemas/index.ts3
4 files changed, 11 insertions, 9 deletions
diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts
index 4493fcc7..8fb86012 100644
--- a/src/api/routes/users/@me/settings.ts
+++ b/src/api/routes/users/@me/settings.ts
@@ -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);
 	},
diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts
index 7f37391a..700a6dae 100644
--- a/src/util/entities/User.ts
+++ b/src/util/entities/User.ts
@@ -453,10 +453,10 @@ export interface UserSettings {
 	gif_auto_play: boolean;
 	// every top guild is displayed as a "folder"
 	guild_folders: {
-		color: number;
+		color?: number;
 		guild_ids: string[];
-		id: number;
-		name: string;
+		id?: number;
+		name?: string;
 	}[];
 	guild_positions: string[]; // guild ids ordered by position
 	inline_attachment_media: boolean;
diff --git a/src/util/schemas/UserGuildSettingsSchema.ts b/src/util/schemas/UserGuildSettingsSchema.ts
index 43028c58..e78bbf7c 100644
--- a/src/util/schemas/UserGuildSettingsSchema.ts
+++ b/src/util/schemas/UserGuildSettingsSchema.ts
@@ -3,7 +3,7 @@ import { UserGuildSettings, ChannelOverride } from "@fosscord/util";
 // This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema
 export interface UserGuildSettingsSchema
 	extends Partial<Omit<UserGuildSettings, "channel_overrides">> {
-	channel_overrides: {
+	channel_overrides?: {
 		[channel_id: string]: Partial<ChannelOverride>;
 	};
 }
\ No newline at end of file
diff --git a/src/util/schemas/index.ts b/src/util/schemas/index.ts
index 8881b247..780022c6 100644
--- a/src/util/schemas/index.ts
+++ b/src/util/schemas/index.ts
@@ -44,4 +44,5 @@ export * from "./ChannelPermissionOverwriteSchema";
 export * from "./UserGuildSettingsSchema";
 export * from "./GatewayPayloadSchema";
 export * from "./RolePositionUpdateSchema";
-export * from "./ChannelReorderSchema";
\ No newline at end of file
+export * from "./ChannelReorderSchema";
+export * from "./UserSettingsSchema";
\ No newline at end of file