summary refs log tree commit diff
path: root/src/api/routes/users/@me
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-28 16:39:26 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-28 16:39:26 +1000
commit419df470a4bb0008d4751a8813164b7b8d4e8554 (patch)
tree8937a55c11bdc5b1508a701ec7bb380e207c1913 /src/api/routes/users/@me
parentMissed some schemas (diff)
downloadserver-419df470a4bb0008d4751a8813164b7b8d4e8554.tar.xz
Fix user guild settings
Diffstat (limited to 'src/api/routes/users/@me')
-rw-r--r--src/api/routes/users/@me/guilds/#guild_id/settings.ts20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/api/routes/users/@me/guilds/#guild_id/settings.ts b/src/api/routes/users/@me/guilds/#guild_id/settings.ts
index 4b806cfb..4538785c 100644
--- a/src/api/routes/users/@me/guilds/#guild_id/settings.ts
+++ b/src/api/routes/users/@me/guilds/#guild_id/settings.ts
@@ -1,22 +1,14 @@
 import { Router, Response, Request } from "express";
 import {
 	Channel,
-	ChannelOverride,
 	Member,
-	UserGuildSettings,
+	OrmUtils,
+	UserGuildSettingsSchema,
 } from "@fosscord/util";
 import { route } from "@fosscord/api";
 
 const router = Router();
 
-// 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_id: string]: Partial<ChannelOverride>;
-	};
-}
-
 // GET doesn't exist on discord.com
 router.get("/", route({}), async (req: Request, res: Response) => {
 	const user = await Member.findOneOrFail({
@@ -30,7 +22,7 @@ router.patch(
 	"/",
 	route({ body: "UserGuildSettingsSchema" }),
 	async (req: Request, res: Response) => {
-		const body = req.body as UserGuildSettings;
+		const body = req.body as UserGuildSettingsSchema;
 
 		if (body.channel_overrides) {
 			for (var channel in body.channel_overrides) {
@@ -40,9 +32,11 @@ router.patch(
 
 		const user = await Member.findOneOrFail({
 			where: { id: req.user_id, guild_id: req.params.guild_id },
+			select: ["settings"]
+
 		});
-		user.settings = { ...user.settings, ...body };
-		await user.save();
+		OrmUtils.mergeDeep(user.settings || {}, body);
+		Member.update({ id: req.user_id, guild_id: req.params.guild_id }, user);
 
 		res.json(user.settings);
 	},