summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 11:10:27 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 11:10:27 +1000
commit544ded68a3cd1d3bb843438f77c95a1e5eb3d941 (patch)
tree2a4e1a7bbbc43aa0563a615f026bbebd286efa5d /api/src
parentCommitted the wrong rights script (diff)
downloadserver-544ded68a3cd1d3bb843438f77c95a1e5eb3d941.tar.xz
Mostly working user guild settings
Diffstat (limited to 'api/src')
-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();