summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--api/assets/schemas.json5
-rw-r--r--api/src/routes/users/@me/guilds/settings.ts28
2 files changed, 33 insertions, 0 deletions
diff --git a/api/assets/schemas.json b/api/assets/schemas.json
index b5dbda31..c8895f3b 100644
--- a/api/assets/schemas.json
+++ b/api/assets/schemas.json
@@ -1136,6 +1136,11 @@
         ],
         "$schema": "http://json-schema.org/draft-07/schema#"
     },
+    "UserGuildSettingsSchema": {
+        "type": "object",
+        "additionalProperties": false,
+        "$schema": "http://json-schema.org/draft-07/schema#"
+    },
     "UserModifySchema": {
         "type": "object",
         "properties": {
diff --git a/api/src/routes/users/@me/guilds/settings.ts b/api/src/routes/users/@me/guilds/settings.ts
new file mode 100644
index 00000000..03029fcc
--- /dev/null
+++ b/api/src/routes/users/@me/guilds/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 },
+		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 } });
+	user.settings = { ...user.settings, ...body };
+	await user.save();
+
+	res.json(user.settings);
+});
+
+export default router;