summary refs log tree commit diff
path: root/api/src/routes/users
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/routes/users')
-rw-r--r--api/src/routes/users/@me/guilds/#guild_id/settings.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/api/src/routes/users/@me/guilds/#guild_id/settings.ts b/api/src/routes/users/@me/guilds/#guild_id/settings.ts
index 1c14bc36..f09be25b 100644
--- a/api/src/routes/users/@me/guilds/#guild_id/settings.ts
+++ b/api/src/routes/users/@me/guilds/#guild_id/settings.ts
@@ -1,10 +1,15 @@
 import { Router, Response, Request } from "express";
-import { Member, UserGuildSettings } from "@fosscord/util";
+import { Channel, ChannelOverride, Member, UserGuildSettings } from "@fosscord/util";
 import { route } from "@fosscord/api";
 
 const router = Router();
 
-export interface UserGuildSettingsSchema extends Partial<UserGuildSettings> { }
+// 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) => {
@@ -15,9 +20,15 @@ router.get("/", route({}), async (req: Request, res: Response) => {
 	return res.json(user.settings);
 });
 
-router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => {
+router.patch("/", route({ body: "UserGuildSettingsSchema" }), async (req: Request, res: Response) => {
 	const body = req.body as UserGuildSettings;
 
+	if (body.channel_overrides) {
+		for (var channel in body.channel_overrides) {
+			Channel.findOneOrFail({ where: { id: channel } });
+		}
+	}
+
 	const user = await Member.findOneOrFail({ where: { id: req.user_id, guild_id: req.params.guild_id } });
 	user.settings = { ...user.settings, ...body };
 	await user.save();