From 1f4f6c555f49c94ac29b00ba069203553b12a611 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 25 Sep 2022 11:10:27 +1000 Subject: Mostly working user guild settings --- api/src/routes/users/@me/guilds/#guild_id/settings.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'api/src') 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 { } +// This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema +export interface UserGuildSettingsSchema extends Partial> { + channel_overrides: { + [channel_id: string]: Partial; + }, +} // 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(); -- cgit 1.5.1