diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-28 16:39:26 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-28 16:39:26 +1000 |
commit | 419df470a4bb0008d4751a8813164b7b8d4e8554 (patch) | |
tree | 8937a55c11bdc5b1508a701ec7bb380e207c1913 | |
parent | Missed some schemas (diff) | |
download | server-419df470a4bb0008d4751a8813164b7b8d4e8554.tar.xz |
Fix user guild settings
-rw-r--r-- | src/api/routes/users/@me/guilds/#guild_id/settings.ts | 20 |
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); }, |