summary refs log tree commit diff
path: root/api
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-21 14:28:05 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-21 14:28:05 +1000
commit64593931531424a51ce07b5b22a4de06a28a00e4 (patch)
treec277835f90d25a7d1fa93d03e96ff2a6e70aafde /api
parentMerge pull request #2 from haydaralqassam/fraudcord (diff)
downloadserver-64593931531424a51ce07b5b22a4de06a28a00e4.tar.xz
Member settings route
Diffstat (limited to 'api')
-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;