summary refs log tree commit diff
path: root/api/src/routes/users/@me/guilds/#guild_id/settings.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-21 15:16:57 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-21 15:16:57 +1000
commit9506d5078208d5d410284b20f11fc965590e0e65 (patch)
tree22bcccccbd357bd5003730854733d063ca125d3b /api/src/routes/users/@me/guilds/#guild_id/settings.ts
parentMore sentry shit (diff)
downloadserver-9506d5078208d5d410284b20f11fc965590e0e65.tar.xz
fix my shit
Diffstat (limited to 'api/src/routes/users/@me/guilds/#guild_id/settings.ts')
-rw-r--r--api/src/routes/users/@me/guilds/#guild_id/settings.ts28
1 files changed, 28 insertions, 0 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
new file mode 100644
index 00000000..1c14bc36
--- /dev/null
+++ b/api/src/routes/users/@me/guilds/#guild_id/settings.ts
@@ -0,0 +1,28 @@
+import { Router, Response, Request } from "express";
+import { Member, UserGuildSettings } from "@fosscord/util";
+import { route } from "@fosscord/api";
+
+const router = Router();
+
+export interface UserGuildSettingsSchema extends Partial<UserGuildSettings> { }
+
+// GET doesn't exist on discord.com
+router.get("/", route({}), async (req: Request, res: Response) => {
+	const user = await Member.findOneOrFail({
+		where: { id: req.user_id, guild_id: req.params.guild_id },
+		select: ["settings"]
+	});
+	return res.json(user.settings);
+});
+
+router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => {
+	const body = req.body as UserGuildSettings;
+
+	const user = await Member.findOneOrFail({ where: { id: req.user_id, guild_id: req.params.guild_id } });
+	user.settings = { ...user.settings, ...body };
+	await user.save();
+
+	res.json(user.settings);
+});
+
+export default router;